Reprinted indicate the source: http://blog.csdn.net/jrckkyy/ http://hi.baidu.com/jrckkyy
Prerequisite: First of all, you must install the network card driver. Needless to say, the commonly used red hat as 4, 5, oracle enterprise are all installed by default with the common network card driver.
Step 1: Check the physical connection of the network card to see if the system recognizes the Ethernet card.
Okay, the second and third lines from the bottom of our cli show that a network card is recognized, the model number is RTL-8139. The link on the hardware is no problem.
Step 2: Use the ifconfig command to check the configuration of the network card
The eth0 Ethernet port is detected.
Step 3: Configure eth0
##Set IP Address##
vi /etc/sysconfig/network-scripts/ifcfg-eth0
or
vi /etc/sysconfig/network-scripts/ifcfg-eteth0
DEVICE=eth0
BOOTPROTO=static #The ip type of the network card is static here, and replaced by dhcp is dynamic
IPADDR=111.111.111.111
NETMASK=255.255.255.0
ONBOOT=yes
##Settings Gateway##
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ippbx
GATEWAY="111.111.111.126"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"
## Setdns ##
vi /etc/resolv.conf
nameserver 111.111.111.1
nameserver 111.111.111.2
##Setupdhcp##
vi /etc/dhcpd.conf
##Restart network##
/etc/init.d/network restart #Restart the entire network device
ifdown eth0 #Close this network card
ifup eth0 #Turn on this network card
Multi-NIC configuration excerpted online:
1. Network card configuration
Assuming that we want to configure the host name test, the IP address of eth0 is 192.168.168.1/24, and the gateway address is 192.168.168.250
, the content of the /etc/sysconfig/network file is as follows: NETWORKING=yes
HOSTNAME=test
GATEWAY=192.168.168.250
The content of the configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 corresponding to eth0 is as follows: DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.168.1
NETMASK=255.255.255.0
TYPE=Ethernet
ONBOOT=yes
Two, single network card binding multiple IP
Sometimes, we need to configure multiple IPs on a network card, for example, in the above example, we also need to configure IP 192.168.168.2 and 192.168.168.3 for eth0. Then you need to create two new configuration files under /etc/sysconfig/network-scripts:
The content of ifcfg-eth0:0 is as follows:
DEVICE=eth0:0
BOOTPROTO=static
IPADDR=192.168.168.2
NETMASK=255.255.255.0
ONBOOT=yes
The content of ifcfg-eth0:1 is as follows:
DEVICE=eth0:1
BOOTPROTO=static
IPADDR=192.168.168.3
NETMASK=255.255.255.0
ONBOOT=yes
Three, multiple network cards are bound into a virtual network card
In order to provide high network availability, we may need to bind multiple network cards into a virtual network card to provide external services, so that even if one of the physical network cards fails, the connection will not be interrupted. For example, we can bind eth0 and eth1 into virtual network card bond0
First, create the configuration file ifcfg-bond0 of the virtual network card bond0 under /etc/sysconfig/network-scripts/, the content is as follows
DEVICE=bond0
BOOTPROTO=none
BROADCAST=192.168.168.255
IPADDR=192.168.168.1
NETMASK=255.255.255.0
NETWORK=192.168.168.0
ONBOOT=yes
TYPE=Ethernet
GATEWAY=192.168.168.250
USERCTL = no
Then modify the configuration files of eth0 and eth1 respectively
ifcfg-eth0 content:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
USERCTL = no
MASTER=bond0
SLAVE=yes
ifcfg-eth1 content
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
USERCTL = no
MASTER=bond0
SLAVE=yes
Because the virtual network card of Linux is implemented in the kernel module, the module is already installed when it needs to be installed. Add the following content to the /etc/modules.conf file (if there is no such file, create a new one):
alias bond0 bonding
options bond0 miimon=100 mode=1 primary=eth0
Where miimon=100 means that the link connection status is checked every 100ms, if it fails, the physical network card will be switched
mode=1 means the main/standby mode, that is, only one network card is active and only fail protection is provided. If mode=0 is the load balancing mode, all network cards are active, and there are other modes that are rarely used
primary=eth0 means that eth0 is the default active network card in the active/standby mode
Finally, add modprobe bonding miimon=100 mode=1 in /etc/rc.local
After restarting the machine, you can see that the virtual network card has taken effect. You can test by plugging and unplugging the network cables of the two physical network cards. However, it seems that the network card takes a long time in Linux.