Network Interface configuration

From LinuxNewbie

Contents

Manually

ifconfig ${DEVICE} ${IPADDR} netmask ${NMASK} broadcast ${BCAST}
route add default gw ${router}
resolv.conf

This example sets interface eth1 to IP 192.168.0.220, adds the gateway 192.168.0.1, and adds its network appropriatly (think subnet mask sort of)

ifconfig eth1 192.168.0.220
route add default gw 192.168.0.1
route add -net 192.168.0.0 netmask 255.255.255.0 eth1


Here is what my config looks like:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
default         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:09:5B:93:E5:9E
          inet addr:192.168.0.192  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::209:5bff:fe93:e59e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5330 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2654 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:875699 (855.1 KiB)  TX bytes:208349 (203.4 KiB)
          Interrupt:11



Debian

Uses a single configuration file, /etc/networking/interfaces
An example /etc/networking/interfaces file

auto lo eth0

iface lo inet loopback

iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        gateway 192.168.1.1

- OR -

auto lo eth0
iface lo inet loopback
iface eth0 inet dhcp


See also Debian Wireless WiFi Configuration File

SuSE


Red Hat/Fedora

Put DNS information in resolv.conf
Edit /etc/sysconfig/network.
Modify: local hostname, domain, and gateway IP. Also, if you plan to do routing, masquerading, etc. you'll need to set FORWARD_IPV4=true in that file.
Example /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=server


While you can change the IP addressing properties of the ethernet card with the ifconfig command, to make the change persistent you must edit /etc/sysconfig/network-scripts/ifcfg-eth0. This file sets: IP addr, netmask, network address, broadcast address, and whether or not IP is set when booting.
Additional interfaces will be named eth1, eth2, etc and have their own appropriately named configuration file.
Example /etc/sysconfig/network-scripts/ifcfg-eth0
Static IP

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.10
NETMASK=255.255.255.0
GATEWAY=192.168.0.1

DHCP IP

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp

For the IP addressing properties of the ethernet card to take effect, and if you are sitting at the console, you can stop and restart networking using /etc/rc.d/init.d/network restart command.
Otherwise you can reboot the machine by typing the command: shutdown -r now. A reboot seems to take around a few minutes, usually less than five minutes.

Slackware

I don't think it could be much easier. type this:

su -
netconfig


That will ask you if it's dhcp, static ip or loopback; if you are using static, it will ask you for a hostname, the ip you want to use, the gateway and the nameserver(s). Then, it will all be set.

Mandrake