Linux networking configuration

When we configure the networking, we need to know about these parameters.
IP, Netmask, Gateway, HostName, DomainName, DNS

1. Network files
)a. /etc/sysconfig/network
/etc/sysconfig/network is to define the hostname

/etc/sysconfig/network configurations as following:
NETWORKING <-if connecting to network
GATEWAY <-default gateway
IPGATEWAYDEV <-default gateway device name
HOSTNAME <-computer name
DOMAIN <-local domain name

)b. /etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts, this file controls the network card configuratons, ifcfg-eth0 is the first device, if you have multiple network cards then the extra will be ifcfg-eth1, ifcfg-eth2 … configurations as following:

DEVICE <-device name
BOOTPROTO <-IP configuration (static: static IP, dhcp: dynamic IP, none: manual)
HWADDR   <- MAC address
ONBOOT    <- enable the device when booting the machine (yes/no)
TYPE          <- network method (normally it should be Ethemet)
NETMASK    <- network netmask number
IPADDR      <- IP number
IPV6INIT    <- If enabling IPV6 (yes/no)
GATEWAY  <- default gateway IP number

Here’s an example configuration
[root@linux ~]# cat -n /etc/sysconfig/network-scripts/ifcfg-eth0
    1 DEVICE=eth0
   2 BOOTPROTO=static
   4 HWADDR=00:0C:2x:6x:0x:xx
   5 IPADDR=
   8 ONBOOT=yes
   9 TYPE=Ethernet

To add more StaticIP on eth0 this card
1. copy the default eth0
2. the default file with configuration is eth0
3. So the second one will be eth0:0
4. the third one is eth0:1

)c. /etc/resolv.conf
this file is to configure the DNS server information
/etc/resolv.conf includes the following settings:
domain ←local domain name
search ←domain name search list
nameserver ←DNS server and it’s IP address (max 3)

)d. /etc/hosts
/etc/hosts is for localhost use purpose (such as,
2. Basic network commands
)a. network service will need to restart in order to apply any change, the command is as following:

[root@linux ~]#/etc/init.d/network restart
you can also use the system service command:
[root@linux ~]#service network restart
start ←start network
stop ←stop network
restart ←restart network
reload ←same as restart
status ←current status

We can also use ifconfigure to start/stop a network device:
[root@linux ~]#ifconfigeth0 down
to put up:
[root@linux ~]#ifconfigeth0 up

You can also use ifconfig to set the machine ip addr, for example we need to set the eth0 ip addr to and netmask we can do this:

[root@linux ~]#ifconfigetho inet netmask
however the setting will be lost after machine reboot.



- has written 121 posts.

Leave a Reply

You must be logged in to post a comment.