Linux Networking 101

Configuring Linux network settings from the command line is pretty easy once you know the location of all the relevant files. This entry will cover the basics of configuring a Redhat Linux system for both DHCP and static IP addresses.

Important Files:

/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth1 (and so on)
/etc/sysconfig/iptables
/etc/hosts
/etc/resolv.conf
/etc/nsswitch.conf

Important commands and scripts:

/sbin/ifconfig
/sbin/mii-tool
/etc/init.d/network {start|stop|restart|reload|status}
/etc/init.d/iptables {start|stop|restart|condrestart|status|panic|save}
/bin/hostname

In the /etc/sysconfig/network file you specify your computer hostname, default gateway, and whether or not networking is enabled.

# /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=host.mydomain.com
GATEWAY=10.200.70.1

In the /etc/sysconfig/network-scripts directory you will find a number of network scripts and configuration files. For each network interface detected by Linux you will see a configuration file. For example, the first network interface (eth0) will have a corresponding config file /etc/sysconfig/network-scripts/ifcfg-eth0.

The file listing below show the configuration for a static IP address. Not all of the parameters are necessary, such as the MAC address. To change your IP address, just edit the corresponding file on your system with the appropriate IP address, subnet mask, etc., and then restart your network settings with service network restart.

# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:11:43:E9:49:82
IPADDR=10.200.70.100
NETMASK=255.255.255.0
NETWORK=10.200.70.0
BROADCAST=10.200.70.255
ONBOOT=yes
TYPE=Ethernet

The ONBOOT parameter tells the system whether or not to enable the interface upon system boot. If you want the interface disabled, just set it to “no”. To configure the interface for DHCP, change the boot protocol setting to “dhcp” and delete most of the other network parameters. It should look something like this:

# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:11:43:E9:49:82
ONBOOT=yes
TYPE=Ethernet

To be able to resolve domain names, enter your DNS server information into /etc/resolv.conf like in the example below.

# /etc/resolv.conf
search mydomain.com
nameserver 10.200.70.10
nameserver 10.200.70.30

The search mydomain.com option specifies your search domain. This domain will be appended to host entries that do not have a fully qualified domain name. For example, if you type ping auth1, the system will append “.mydomain.com” if it can’t find “auth1″. Changes to /etc/resolv.conf take affect immediately.

To start and stop networking use the network startup script located in /etc/init.d/ either directly, or through the service command.

[root@host]# service network
Usage: /etc/init.d/network {start|stop|restart|reload|status}
[root@host]# service network restart
[root@host]# /etc/init.d/network restart  (same thing)

Two other useful commands to know are ifconfig and mii-tool. Read the man pages for both for detailed information. ifconfig allows you to view current network interface settings, modify IP settings on the fly, shut down interfaces, etc. mii-tool allows you to view and modify the speed and duplex settings of your interfaces.

That’s the basics. The other files are related to networking but I won’t go into them here other than to give basic descriptions.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)