zellda's

notes on Linux

Static IP and Proxy Config for Ubuntu, Debian, CentOS

A while ago I had to install CentOS on a windows hyper drive. As CentOS does not support hyper drive out of the box like ubuntu does I had to configure the network card from scratch. Here’s what you have to do in such a case:

Configure a static IP-address (IPs are examples):

CentOS

Terminal
1
vi /etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
6
7
8
DEVICE=”eth0″
ONBOOT=”yes”
TYPE=”Ethernet”
BOOTPROTO=”static”
NETWORK=”10.161.2.0″
NETMASK=”255.255.255.0″
IPADDR=”10.161.2.14″
USERCTL=”no”
Terminal
1
vi /etc/sysconfig/network
/etc/sysconfig/network
1
2
3
4
5
6
7
NAME=”System eth0″
NETWORKING=”yes”
GATEWAY=”10.161.2.1″
HOSTNAME=”machine”
vi /etc/resolv.conf
search your-dns-search-path
nameserver 10.161.2.4
Terminal
1
/etc/init.d/network restart

Debian / Ubuntu

Terminal
1
vi /etc/network/interfaces
/etc/network/interfaces
1
2
3
4
5
6
## iface eth1 inet dhcp ## dynamic
iface eth1 inet static
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255
Terminal
1
2
/etc/init.d/networking stop
/etc/init.d/networking start

or

Terminal
1
2
sudo ifdown eth0
sudo ifup eth0

(/etc/init.d/networking restart is deprecated it seems)

Set up a second or virtual IP address:

Terminal
1
vi /etc/network/interfaces
/etc/network/interfaces
1
2
3
4
5
6
7
auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x

Proxy config (CentOS and others):

Terminal
1
vi /etc/environment
/etc/environment
1
2
3
4
5
6
http_proxy=”http://10.160.1.1:8080″
ftp_proxy=”ftp://10.160.1.1:8080″
https_proxy=”https://10.160.1.1:8080″
no_proxy=”localhost”
no_proxy=”127.0.0.1″
no_proxy=”*.example.local”

yum:

Terminal
1
vi /etc/yum.conf
add to yum config file:
1
2
proxy=http://10.160.1.1:8080
proxy=ftp://10.160.1.1:8080

apt:

Terminal
1
vi /etc/apt/apt.conf
add to apt config file:
1
2
3
Acquire::http::proxy “http://user:pass@ip:port/”;
Acquire::https::proxy “https://user:pass@ip:port/”;
Acquire::ftp::proxy “ftp://user:pass@ip:port/”;

General:

Terminal
1
vi /etc/bash.bashrc

or

Terminal
1
vi /etc/profile
add to /etc/profile or tolink
1
2
export HTTP_PROXY=http://username:password@proxyserver.net:port/
export FTP_PROXY=http://username:password@proxyserver.net:port/

Nice:
Add the following to /etc/bash.bashrc

/etc/bash[.]bashrc
1
2
3
4
5
6
7
8
9
function proxy(){
echo -n “username:”
read -e username
echo -n “password:”
read -es password
export http_proxy=”http://$username:$password@proxyserver:8080/”
export ftp_proxy=”http://$username:$password@proxyserver:8080/”
echo -e “\nProxy environment variable set.”
}

Then whenever you want to set the proxy variable you just type “proxy” at the command line. When prompted for your proxyserver user name you type it in (you may need to type domain\user if it’s a domain account) and then when prompted type your password (which isn’t echoed to the screen).
This will then set the environment variables, and they’ll be lost when you exit your session.

Have fun!

Comments