Key Concepts, Class 3 – Part 2:  Managing UNIX Network Settings

 

Overview

 

- IP address

- Subnet Mask

- Broadcast Address, if available

- Default Gateway (sometime referred to as your Default Router)

- One or more DNS server (sometimes called name servers)

 

This information is usually available from your network administrator or Internet service provider.   When you have a dedicated IP address that is assigned to you and never changes, we say that you have a static IP address.

 

 

Important Network Configuration Files for Linux

 

/etc/sysconfig/network

The /etc/sysconfig/network file is used to enable networking on bootup, specify your default gateway and the network adapter associated with your default gateway.  Here’s a look at the file with comments that explain what each line means.

 

[chrisjur@ sysconfig]$ more /etc/sysconfig/network

 

#Tells Linux whether to enable networking on boot

NETWORKING=yes         

#Enables IP Forwarding – this line is not #required

FORWARD_IPV4=true     

#The hostname of your computer

HOSTNAME=mycomputer    

#The domain name associated with your computer, if you have one

DOMAINNAME=localdomain     

# The default gateway assigned to you by your ISP

GATEWAY=10.0.0.254

#The name of the NIC card that is attached to your default gateway

GATEWAYDEV=eth0     

 

 

/etc/sysconfig/network-scripts/ifcfg-eth0

The /etc/sysconfig/network-scripts/ifcfg-eth0 file is used to configure your primary NIC card, eth0.  There are similar configuration files for each NIC you have installed on the system (e.g. /etc/sysconfig/network-scripts/ifcfg-eth1 configures the eth1 adapter).  This file is where you specify IP address, broadcast address and netmask info.  Here is a sample of the file with comments for each line:

 

[chrisjur@ sysconfig]$ more /etc/sysconfig/network-scripts/ifcfg-eth0

#Specifies the name of the network card you are configuring

DEVICE=eth0

#Tells Linux which boot protocol you are using. 

#If you have a static IP address, this is an optional line. 

# If you are using DHCP, it should be set to ‘dhcp’

BOOTPROTO=none

#Put your IP address here

IPADDR=145.16.122.254

#Put your netmask here

NETMASK=255.255.255.0

#Put your network address here

NETWORK=145.16.122.0

#Put your broadcast address here

BROADCAST=145.16.122.255

#Tells Linux to activate this card when the machine boots up

ONBOOT=yes

 

 

 

/etc/resolve.com

This file contains the list of your DNS servers.  It is in the format:

 

nameserver <nameserver ip address>

nameserver <nameserver ip address>

 

e.g.:

 

nameserver 167.206.112.4

nameserver 167.206.112.3

 

You can specify as many nameserver IP addresses as you wish within this file.  Keep in mind that you can only have one ‘nameserver’ entry per line in this file.

 

 

 

/etc/hosts

The /etc/hosts file contains a list of hostnames (system names) and their associated IP addresses.  It is in the format:

 

127.0.0.1         localhost  

IP address        system-name  system-alias1   system-alias2

IP address        system-name  system-alias1   system-alias2

IP address        system-name  system-alias1   system-alias2

IP address        system-name  system-alias1   system-alias2

 

e.g.

 

127.0.0.1             localhost

10.0.0.254            your-system-name

192.168.99.1                        some-other-system

 

There should always contain the line:

 

127.0.0.1             localhost

 

There must also be a line that contains your system hostname and IP addresses.

 

 

/etc/nsswitch.conf

This file tells the system how it should perform name resolution (hostname to IP address translation), among other things.  There is one very important line in this file:

 

hosts:      files dns nisplus nis

 

This line tells the system to search perform hostname resolution in a specific order.  First, the system will look in the /etc/hosts file (set by the ‘file’ directive) and then will perform a full DNS lookup if it can’t find the hostname-IP address pair in that file.  Finally, the system will attempt nisplus and nis name resolutions, if these services are available.   It is not necessary to have ‘nisplus’ and ‘nis’ directives on this line, but it is very important that the ‘files’ and ‘dns’ directives are included.

 

Most of the time, you do not have to edit this file at all.  Solaris systems are famous for shipping nsswitch.conf files that do not contain a ‘hosts:’ line with ‘dns’ and ‘files’ options specified.

 

 

Examples

 

You are going to your new Linux system with the hostname ‘thor’.  Your network admin or ISP assigns you the following network settings:

 

IP Address:  10.221.49.112

Gateway: 10.221.49.254

Netmask: 255.255.255.0

Network Address:  10.221.49.0

Broadcast Address: 10.221.49.255

DNS Server: 206.20.36.1, 206.20.36.150

 

 

Using these network specs, your configuration files will look like this:

 

/etc/sysconfig/network:

NETWORKING=yes         

FORWARD_IPV4=true     

HOSTNAME=thor    

DOMAINNAME=localdomain     

GATEWAY=10.221.49.254

GATEWAYDEV=eth0        

 

/etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0

BOOTPROTO=none

IPADDR=10.221.49.112

NETMASK=255.255.255.0

NETWORK=10.221.49.0

BROADCAST=10.221.49.255

ONBOOT=yes

 

/etc/sysconfig/network-scripts/ifcfg-eth0:

127.0.0.1            localhost

10.221.49.112                    thor

 

/etc/resolve.conf:

nameserver        206.20.36.1

nameserver        206.20.36.150

 

/etc/nsswitch.conf (hosts: line only showed)

hosts:      files      dns