Once We have installed CentOS and now you’d like to either change the IP address or add additional LAN cards (NIC). There are a couple of ways to configure the network card using the command line but only some commands will take immediate effect on kernel
Configure network with immediate effect
Using a single command line to configure the network
# ifconfig eth0 192.168.0.10 netmask 255.255.255.0
[or]
# ip addr add 192.168.0.10 dev eth0
Configure network with setup or netconfig
If We are using netconfig (or) setup utility it will only overwrite the /etc/sysconfig/network-scripts/ifcfg-eth0 file. Then , after that we have to restart the network service like follow,
# setup
Network configuration -> Edit Devices -> eth0 (eth0) – Intel Corporation 82540EM Gigabit Ethernet Controller
Save your settings and quit
[or]
# system-config-network
Edit Devices -> eth0 (eth0) – Intel Corporation 82540EM Gigabit Ethernet Controller
Save your settings and quit
Restart your network in order for your configuration to take effect.
# /etc/init.d/network restart
/dev/hde1
/dev/hdf2
/dev/hdg1
Configure network by editing configuration
Lastly we can configure the network by editing the configuration files stored in the /etc/sysconfig/network-scripts/ directory.
# cd /etc/sysconfig/network-scripts/
# vi ifcfg-eth0
Append/modify as follows:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=05:09:18:a9:34:11
NETMASK=255.255.255.0
IPADDR=192.168.0.10
TYPE=Ethernet
Save and close the file. Define default gateway and hostname in /etc/sysconfig/network configuration file
# vi /etc/sysconfig/network
Append/modify configuration as follows:
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=example.nextstep4it.com
GATEWAY=192.168.0.1
Save and close the file. Restart networking:
# /etc/init.d/network restart
Network Bonding :- NIC teaming or network bonding is nothing but combining or aggregating multiple network connections in parallel. This is done to increase throughput, and to provide redundancy in case one of the links fails or Ethernet card fails. The Linux kernel comes with the bounding driver for aggregating multiple network interfaces into a single logical interface called bond0.
Bonding is nothing but Linux kernel feature that allows to aggregate multiple like interfaces (such as eth0, eth1) into a single virtual link such as bond0. The idea is pretty simple get higher data rates and as well as link failover. Steps To Configure Bonding in Linux
Step #1: Create a Bond0 Configuration File, CentOS stores network configuration in /etc/sysconfig/network-scripts/ directory. First, we need to create a bond0 config file as follows:
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
Append the following lines:
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
You need to replace IP address with your actual setup. Save and close the file.
Step #2: Modify eth0 and eth1 config files
Open both configuration using a text editor such as vi/vim, and make sure file read as follows for eth0 interface
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify/append directive as follows:
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
Open eth1 configuration file using vi text editor, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
Make sure file read as follows for eth1 interface:
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
Save and close the file.
Step # 3: Load bond driver/module
Make sure bonding module is loaded when the channel-bonding interface (bond0) is brought up. You need to modify kernel modules configuration file:
#vi /etc/modprobe.conf
Append following two lines:
alias bond0 bonding
options bond0 mode=balance-alb miimon=100
Save file and exit
Step # 4: Test configuration
First, load the bonding module, enter:
# modprobe bonding
Restart the networking service in order to bring up bond0 interface, enter:
# service network restart
Make sure everything is working. Type the
following cat command to query the current status of Linux kernel bounding driver, enter:
# cat /proc/net/bonding/bond0
Sample outputs:
Bonding Mode: load balancing (round-robin)
MII Status: up
To list all network interfaces, enter:
# ifconfig
Sample outputs:
bond0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:2804 errors:0 dropped:0 overruns:0 frame:0
TX packets:1879 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:250825 (244.9 KiB) TX bytes:244683 (238.9 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2809 errors:0 dropped:0 overruns:0 frame:0
TX packets:1390 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:251161 (245.2 KiB) TX bytes:180289 (176.0 KiB)
Interrupt:11 Base address:0x1400
eth1 Link encap:Ethernet HWaddr 00:0C:29:C6:BE:59
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fec6:be59/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:502 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:258 (258.0 b) TX bytes:66516 (64.9 KiB)
Interrupt:10 Base address:0x1480
Source:- www.nextstepit.com