Linux operation and maintenance tutorial-Linux system network management

Linux system network management

  • What is the network?

  • Network card configuration file

  • nmcli


The internet

  • IP address: The address used to identify the machine, similar to an ID number. The only public network in the world ipv4 ipv6

  • DNS: domain name service, which resolves the domain name of a website to the host of the website

  • Gateway: Gateway, our router is the gateway.


ifconfig: View all network card information

ifconfig ens33: View the information of the fixed network card

ip addr: view network card information



Network card configuration file

/etc/sysconfig/network-scripts

ens33 == ifcfg-ens33

ens35 == ifcfg-ens35

TYPE="Ethernet" 
PROXY_METHOD="none"  
BROWSER_ONLY="no"
BOOTPROTO="none" ##none static static dhcp dynamic  
DEFROUTE="yes" ## Default routing
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes "
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33" ## NIC name
UUID="e20ba92f-11c2-49b4-8542-36b5a3879173" ## NIC UUID unique
DEVICE="ens33"
ONBOOT="yes" ## yes Turn on the network card automatically when booting
IPADDR=192.168.1.199 ## IP address
NETMASK=255.255.255.0 ## Subnet mask


centos7: systemctl restart network

nmcli


nmcli c reload
nmcli c up xxx




experiment

Add an experimental network card

  • Modify the IP address to

    192.168.1.188
    255.255.255.0
    192.168.1.1
  • cp ifcfg-ens33 ifcfg-ens37
  • [root@myserver network-scripts]# cat ifcfg-ens37
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    BOOTPROTO="none"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    IPV6_ADDR_GEN_MODE="stable-privacy"
    NAME="ens37"
    DEVICE="ens37"
    ONBOOT="yes"
    IPADDR=192.168.1.188
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1


nmcli c reload
ifdown ens37
ifup ens37


[root@myserver network-scripts]# ifdown ens37
Connection 'ens37' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[root@myserver network-scripts]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      ether 00:0c:29:94:17:3a txqueuelen 1000 (Ethernet)
      RX packets 182 bytes 19010 (18.5 KiB)
      RX errors 0 dropped 0 overruns 0 frame 0
      TX packets 286 bytes 31958 (31.2 KiB)
      TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@myserver network-scripts]# ifup ens37
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
[root@myserver network-scripts]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      inet 192.168.1.188 netmask 255.255.255.0 broadcast 192.168.1.255
      inet6 fe80::8568:3e1a:817f:59c0 prefixlen 64 scopeid 0x20<link>
      ether 00:0c:29:94:17:3a txqueuelen 1000 (Ethernet)
      RX packets 193 bytes 19790 (19.3 KiB)
      RX errors 0 dropped 0 overruns 0 frame 0
      TX packets 306 bytes 34192 (33.3 KiB)
      TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0




nmcli



View network card information 
# nmcli connection
# nmcli con xxx

displays specific network interface information
# nmcli connection show xxx

displays all active connections
# nmcli connection show --active

deletes a network card connection
# nmcli connection delete

ens37 adds an IP (IPADDR) to ens37
# nmcli connection modify ens37 ipv4.addresses 192.168.1.189

add a subnet mask to xxx (NETMASK)
# nmcli connection modify ens37 ipv4.addresses 192.168.1.189/24

IP acquisition mode is set to manual (BOOTPROTO=static/none)
# nmcli connection modify ens37 ipv4.method manual

add an ipv4
# nmcli connection modify ens37 +ipv4.addresses 192.168.1.189/24

delete an ipv4
# nmcli connection modify ens37 -ipv4.addresses 192.168.1.189/24


add a gateway (GATEWAY)
# nmcli connection modify ens37 ipv4.gateway 192.168.0.2

can be written in one piece:
# nmcli connection modify ens37 ipv4.dns 114.114.114.114 ipv4.gateway 192.168.0.1

add DNS
# nmcli connection modify ens37 ipv4.dns 114.114.114.114

delete DNS
# nmcli connection modify ens37 -ipv4.dns 114.114.114.114


Use nmcli to
reload the network configuration # nmcli c reload

If there is no xxx connection before, it will automatically take effect after the previous reload

# nmcli c up ens37



[root@myserver ~]# cd /etc/sysconfig/network-scripts/
[root@myserver network-scripts]# ls
ifcfg-ens33  ifcfg-ens37  ifcfg-ens37-1
[root@myserver network-scripts]# mv ifcfg-ens37 ifcfg-ens37~~~~
[root@myserver network-scripts]# ls
ifcfg-ens33  ifcfg-ens37~~~~  ifcfg-ens37-1
[root@myserver network-scripts]# cd
[root@myserver ~]#
[root@myserver ~]# nmcli connection modify ens37  ipv4.addresses  192.168.1.189
[root@myserver ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.188  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::20c:29ff:fe94:173a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:94:17:3a  txqueuelen 1000  (Ethernet)
        RX packets 449  bytes 47699 (46.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 530  bytes 59159 (57.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@myserver ~]# nmcli connection reload
[root@myserver ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.188  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::20c:29ff:fe94:173a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:94:17:3a  txqueuelen 1000  (Ethernet)
        RX packets 458  bytes 48335 (47.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 530  bytes 59159 (57.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@myserver ~]# nmcli connection up ens37
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
[root@myserver ~]# ifconfig ens37
ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.189  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::20c:29ff:fe94:173a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:94:17:3a  txqueuelen 1000  (Ethernet)
        RX packets 500  bytes 52058 (50.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 582  bytes 64767 (63.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


Guess you like

Origin blog.51cto.com/15127507/2656573