Detailed Network configuration in CentOS7

Source: Internet
Author: User

First, preface


Originally prepared to write some network configuration tool use, and then think about (in fact, to be lazy), online about NMCLI tool use of the article is not much, so write a CentOS7 in the NMCLI tool simple use and CentOS7 some of the network property configuration related changes.



Ii. changes in the CENTOS7 network


Many friends just contact CentOS7 when the most unaccustomed is its network card naming method, but not accustomed to eventually still have to understand it, after all, an operation and maintenance personnel to keep the advanced, we together to understand the CentOS7 in the name of the network card!




Network card naming mechanism


    1. If the index information for an integrated device on the firmware or BIOS board is available and predictable, the index is named according to

    2. If the index information provided by the firmware or BIOS for the PCI-E expansion slot is available and predictable, it is named according to this index

    3. If the physical location information for the hardware interface is available, it is named according to this information, such as ENP2S1 (an Ethernet device that represents the first index number on the second PCI-E slot)

    4. If the user is explicitly available, it can also be named according to the MAC address

    5. None of the above is available before using the traditional eth0 ... to name




Question: Why do you use this naming mechanism in CentOS7?


Before CentOS7 we used the network card naming mechanism is a lot of problems, for example: if there are two network cards, respectively, eth0 and eth1, assuming that the eth0 NIC is broken, we will replace it, change the new network card, we may find that the new network card has become eth2, This will cause a lot of problems when we manage the configuration network again.

And CentOS7 in the naming method will not have this problem, in general, as long as your interface does not change, there will be no change in the name of the network card.




CENTOS7 NIC Name composition format

En: Indicates Ethernet, Ethernet WL: For WLAN, wireless network ww: for Wwan, unlimited WAN o: Device index number representing an integrated device s: Index number representing the expansion slot x: Indicates a MAC address named PS: Indicates the index number on the bus on the motherboard



Udev uses Udev to read/lib/udev/rename_device,/usr/lib/udev/rules.d/60-net.rules to name the NIC device Biosdevname if the data is not detected in the first step, according to the/usr/ Lib/udv/rules.d/71-biosdevname.rules the information in the file to name the NIC device detection network device interface if the data is not detected in the second step, the NIC device interface is detected through Udev, according to/usr/lib/udev-rules.d/ Description of the NIC device in 75-net-description to name the NIC device using the traditional naming method if all of the above methods are detected, then the traditional network card naming method is returned.


Third, CentOS7 return to the traditional network card naming method


In fact, if you really do not like the CentOS7 network card naming method we can also change back to the traditional naming method



1. Edit the/etc/default/grub configuration file

[[email protected] ~]# vim/etc/default/grubgrub_timeout=5grub_distributor= "$ (SED ' s, release. *$,,g '/etc/ system-release) "grub_default=savedgrub_disable_submenu=truegrub_terminal_output=" Console "GRUB_CMDLINE_LINUX=" Net.ifnames=0 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet "#在前面添加net. Ifnames=0grub_disa Ble_recovery= "true"


2. Generate its configuration file for Grub2

[Email protected] ~]# grub2-mkconfig >/etc/grub2.cfg #重建grub2配置重定向到原始配置文件Generating grub configuration file ... Found Linux Image:/boot/vmlinuz-3.10.0-327.el7.x86_64found initrd Image:/boot/initramfs-3.10.0-327.el7.x86_64. Imgfound Linux Image:/boot/vmlinuz-0-rescue-ec3b02cacfc74b14822e17fb4079710bfound initrd Image:/boot/ Initramfs-0-rescue-ec3b02cacfc74b14822e17fb4079710b.imgdone[[email protected] ~]#

3. Restart the system

[[email protected] ~]# ifconfig      #网卡以命名成eth0eth0:  flags=4163 <UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500         inet 192.168.192.132  netmask 255.255.255.0  broadcast  192.168.192.255        inet6 fe80::20c:29ff:fed1:44a3   prefixlen 64  scopeid 0x20<link>         ether 00:0c:29:d1:44:a3  txqueuelen 1000   (Ethernet)          RX packets 75  bytes 8491  (8.2 kib)          rx errors 0  dropped 0  overruns 0   frame 0        TX packets 90   bytes 14146  (13.8 kib) &NBSP;&NBSp;      tx errors 0  dropped 0 overruns 0   carrier 0  collisions 0



Address Configuration Tool: Nmcli Brief Introduction

The NMCLI tool is a command-line configuration tool provided by NetworkManager, and we have only some of its simple usage here, and this blog post may be updated later to fully explain the nmcli.


NMCLI [OPTIONS] OBJECT {COMMAND | help} #nmcli语法



Configure the IP address of the eth0 to 192.168.1.1/24

Nmcli con modify eth0 ipv4.addresses 192.168.1.1/24


Configure the gateway address of the eth0 to 192.168.1.254

Nmcli con modify eth0 ipv4.gateway 192.168.1.254


Set the dns1 of Eth0 to 202.102.192.68,dns2 set to 8.8.8.8

Nmcli con modify eth0 ipv4.dns 202.102.192.68 dns2 8.8.8.8


Add a connection,ip called Eth0-2 on the eth0 device to 172.16.100.1/24 Gateway 172.16.100.254

Nmcli con add con-name eth0-2 type Ethernet IP4 172.16.100.1/24 Gateway 172.16.100.254nmcli con up eth0-2 #启动eth0-2 configuration, Note that the configuration of an interface can start only one


Set the connection named Eth0 on the eth0 device to the DHCP get address

Nmcli con eth0 modify Ipv4.method Auto



Summarize

This writing is really not very good, less write a lot of rewriting things, may add some of the NMCLI tools for a comprehensive introduction, writing this article has been 11 o'clock, I am too tired, simply released first, I hope you understand.

This article is from the "The Anyisalin blog" blog, please be sure to keep this source http://anyisalin.blog.51cto.com/10917514/1749350

Detailed Network configuration in CentOS7

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.