How to configure networking

To configure a network interface to use DHCP:

auto eth0
iface eth0 inet dhcp
        dns-nameservers 192.168.1.254

Or on Etch with hotplug:

allow-hotplug eth0
iface eth0 inet dhcp

To statically configure a network interface:

auto eth0
iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        gateway 192.168.1.254
        broadcast 192.168.1.255
        dns-nameservers 192.168.1.254

Then if you have previously used DHCP then until you reboot dhclient will still be running and so you should kill it:

ps ax | grep dhclient
kill -9 12345

IP Aliases

Configure the IP alias in /etc/network/interfaces as shown below:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# Automatically bring up the following interfaces
auto lo eth0 eth0:0

# The loopback network interface
iface lo inet loopback

# The primary network interface
# allow-hotplug eth0
# iface eth0 inet dhcp

# Primary interface
iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        gateway 192.168.1.254
        broadcast 192.168.1.255
        dns-nameservers 192.168.1.254
        
# Alias
iface eth0:0 inet static
        address 192.168.1.2
        netmask 255.255.255.0

To remove an IP alias you sometimes need to force it to go down:

ifdown --force eth0:0
ip link set eth0:0 down

Disable ARP Broadcasts

When using some types of load-balancers you need to configure the same IP address on the load-balancer and both web-servers.

To do that you need to disable ARP broadcasts on the web-servers so that they don't compete with the load-balancer for control of the IP address to MAC address mapping on the switch.

You can do this in /etc/network/interfaces as follows:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# Automatically bring up the following interfaces
auto lo eth0 eth0:0

# The loopback network interface
iface lo inet loopback

# The primary network interface
# allow-hotplug eth0
# iface eth0 inet dhcp

# Primary interface
iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        gateway 192.168.1.254
        broadcast 192.168.1.255
        dns-nameservers 192.168.1.254
        up echo 3 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
        up echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce

# Alias
iface eth0:0 inet static
        address 192.168.1.2
        netmask 255.255.255.0

Once you restart networking or reboot you should fine that the appropriate kernel settings have been changed from their default values, and can check that as follows:

cat /proc/sys/net/ipv4/conf/eth0/arp_ignore
cat /proc/sys/net/ipv4/conf/eth0/arp_announce

If your using the Shorewall firewall then you may find that the above change has not taken effect, this is because Shorewall is overriding the setting. To fix that edit /etc/shorewall/interfaces as follows:

#ZONE   INTERFACE       BROADCAST       OPTIONS
net     eth0            detect          dhcp,tcpflags,[...],arp_ignore=3 

Note that we've simply added arp_ignore=3 to the list of options. Restart shorewall and check the kernel setting once more.

Discussion

kresh, 2009/01/27 07:25:
I would like to know how to configure eth0 on sun solaris
kresh, 2009/01/27 07:26:
network configuration in unix
Andy, 2009/04/07 22:45:

Hello kresh, I'm sorry I don't know much about Solaris. The /etc/network/interfaces file is Debian specific but you should be able to use the ip command to configure networking on just about any flavour of Unix. For example see ip addr show.

Enter your comment (wiki syntax is allowed):

Subscribe to the RSS feed for Andy's Debian HOWTOs

Article from Andy's Debian HOWTOs (http://www.besy.co.uk/debian/debian)

 
debian/how_to_configure_networking.txt · Last modified: 2009/09/30 14:36 by andy · [Old revisions]
Recent changes RSS feed Powered by Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki