Tag Archive | "linux networking"


Auto configure multiple IPs under Linux

Generally, if you want to configure multiple IPs to the same network card, you need to write the configuration files one by one. It’s ideally to run a script and it will auto configure everything. Here is a sample script.

1. Create the range script under /etc/sysconfig/network-scripts

# vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0


2. Quit and restart the network service, the system will auto configure each IP started from eth0:1

# service network restart

Some NETMASK reference.

/29 (5 usable) NETMASK =
/28 (13 usable) NETMASK =
/27 (29 usable) NETMASK =
/26 (61 usable) NETMASK =
/25 (125 usable) NETMASK =
/24 (253 usable) NETMASK =

The first two IPs (network & gateway) and the last IP (broadcast) in your assignment are unusable for you.


Posted in Linux-Apache-PHPComments (0)


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.



Posted in Linux-Apache-PHPComments (1)