Linux-related network interface configuration

Source: Internet
Author: User

In Linux network interface configuration file is generally in a file, set the interface, device name, scheme name, IP address acquisition mode, whether to automatically assign IP when the boot, and so on, all of these settings are in the configuration file/etc/sysconfig/network-script, Want to set the network card to find its corresponding files can be edited, speaking of network cards, in real life in order to improve the redundancy of the network card to prevent the occurrence of single point of failure, we usually have to adapt to the needs of real life, the network card related settings, and then we are familiar with the relevant commands.

First, the network card itself related commands

    • Ifconfig to view information about the associated network card on this virtual machine

If the ifconfig command does not follow anything, it will show all the network card information, if the ifconfig followed by the device name, display the information about the specified network card.

    • Cd/etc/sysconfig/network-scripts to view the configuration files under this directory
[[email protected] network-scripts]#detailed configuration of cat Ifcfg-eth0 eth0Device=eth0 device name Hwaddr=00:0c:29:6a:7a:68the MAC address of the NIC is type=Ethernet Device type is Ethernetuuid=158888e2-4c5d-4859-8be8-903cee9f7c7aonboot=Yes indicates whether the NIC is started with the network service start nm_controlled=No indicates whether the NIC supports NetworkManager management, the default yes is support, and no is not supported. Bootproto=dhcp|static|None if the row is deleted, set the ipaddr manually=6.6.6.6NETMASK=255.255.255.0manually set address and mask Userctrl=Yes the switch of the NIC is adjusted by the normal user Peerdns=no default Yes when the network adapter starts, and Peerdns=yes, the DNS configuration file DNS is overwritten by the network card's DNS settings, if the NIC is DHCP is overwritten by the DHCP settings, if the network card is a static address, DNS overrides are statically configured
    • Setting aliases for network cards
[[email protected] network-scripts]#ifconfig eth0:0 172.17.2.241/24[Root@localhost Network-scripts]#Vim ifcfg-eth0:0DEVICE=eth0:0TYPE=Ethernetonboot=yesnm_controlled=yeshwaddr=00:0c:29:77: 8e:c9defroute=Yespeerdns=yespeerroutes=Yesipv4_failure_fatal=Yesipv6init=noipaddr=172.17.2.241NETMASK=255.255.255.0NAME="System eth0"

Second, the configuration bond

Bond is configured primarily to improve redundancy, but the CENTOS6 on and Centos7 on the bond configuration is not the same, the next is shown separately.

    • Configuring Bond on CENTOS6

1. Add two NICs to the virtual machine.

2. Create a bond0 file

[[email protected] network-scripts] # CP Ifcfg-eth0 Ifcfg-bond0 [Root@localhost network-scripts] # Vim ifcfg-bond0 device=bond0          device name modified to bond0bonding_opts="miimon=100 mode=1"      Bond this trip is key type=ethernetipaddr=20.20.20.6NETMASK=255.255.255.0onboot= yesnm_controlled=no

3, add two Nic, respectively, Eth2 and Eth3, they are used to do slave, after copying the relevant configuration

[[email protected] network-scripts]#CP Ifcfg-eth0 Ifcfg-eth2[Root@localhost Network-scripts]#Vim Ifcfg-eth2Device=Eth2type=Ethernetonboot=Yesslave=Yes key line, agree for Slavemaster=bond0 Manager for bond0nm_controlled=No[root@localhost Network-scripts]#CP Ifcfg-eth0 Ifcfg-eth3[Root@localhost Network-scripts]#Vim Ifcfg-eth3Device=Eth3type=Ethernetonboot=Yesslave=Yes key line, agree for Slavemaster=bond0 Manager for bond0nm_controlled=no

4. Restart the Network Service

[[email protected] network-scripts] # Service Network Restart
    • CENTOS7 Configuring Bond

1, add two network cards

2. Add Bond Scheme

[[Email protected] ~] # nmcli Connection Add con-name BOND0 ifname bond0 type bond mode Active-backup

3, increase the slave of the scheme to two new cards added

[[Email protected] ~] # nmcli Connection Add con-name SLAVE-38 ifname ens38 type Ethernet Master Bond0 [root@localhost ~] # nmcli Connection Add con-name SLAVE-39 ifname ens39 type Ethernet Master Bond0

4, Configuration Bond0

[[Email protected] ~] # nmcli Connection Modify bond0 ipv4.method manual connection.autoconnect Yes ipv4.addresses 20.20.20.20/24 Ipv4.dns 8. 8.8.8 Ipv4.gateway 20.20.20.1

5. Direct activation of BOND0

[[Email protected] ~] # nmcli connection up bond0  for slaves) (D-bus active path:/org/freedesktop/networkmanager/activeconnection/27) [Root@ localhost ~]#ifconfig bond0

Three, for a network card configuration two scenarios

1. Modify the old NIC name

[[email protected] network-scripts] # nmcli Connection Modify ENS33 Connection.id class [Root@localhost network-scripts] # MV Ifcfg-ens33 Ifcfg-class

2. Automatically get the IPv4 address for the program settings of class

[[email protected] network-scripts] #

3. Making the programme effective

[[email protected] network-scripts] # NMCLI connection up class

4. The new scheme is called home

[[email protected] network-scripts] # nmcli Connection Add con-name Home type Ethernet ifname ens33

5, set the new scheme for static access to address

[[email protected] network-scripts] # nmcli Connection Modify Home Ipv4.method manual Connection.autoconnect Yes ipv4.addresses 8.8.8.8/24 ipv4.gateway 8. 8.8.1 Ipv4.dns 4.4.4.4

6. Switch to the new program to make it effective

[[email protected] network-scripts] # nmcli connection up home

IV. Create Network Group (team) to improve NIC performance

1. Create Team plan

[[email protected] network-scripts] # nmcli Connection Add con-name team0 type team ifname team0 config  ' {"Runner": {"name": "LoadBalance"}} '

2. Create a Slave scheme and specify master

[[email protected] network-scripts] # nmcli Connection Add con-name slave-38 type Team-slave ifname ens38 master Team0 [Root@localhost network-scripts] # nmcli Connection Add con-name slave-39 type Team-slave ifname ens39 master Team0

3, set the IP team0

[[email protected] network-scripts] # nmcli Connection Modify TEAM0 ipv4.method manual connection.autoconnect Yes ipv4.addresses 20.20.20.20/24

4. Activating team0 and slave

[[email protected] network-scripts] # nmcli connection up Team0 [Root@localhost network-scripts] # nmcli connection up slave-38 [Root@localhost network-scripts] # nmcli connection up slave-39

The team was created successfully at this time. This concludes with a description of the NIC configuration.

Linux-related network interface configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.