Linux dynamic network configuration

CentOS physical machine command version network configuration details:

centos6: vim /etc/sysconfig/network-scripts/ifcfg-eth0 (network card name)

centos7: vim /etc/sysconfig/network-scripts/ifcfg-ens33 (network card name)

1. Execute with the highest authority root:

  1. [dell@localhost ~]$ about
  2. password:

2. View the network card name:

Line 8 of the code block (2: ens32) is the network card name, and so on if there are other network ports! !

[root@localhost dell]# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:24:17:1c brd ff:ff:ff:ff:ff:ff

    inet 192.168.10.11/24 brd 192.168.10.255 scope global noprefixroute dynamic ens32

       valid_lft 7172sec preferred_lft 7172sec

    inet6 fe80::bdd9:140c:83f:43d8/64 scope link noprefixroute 

       valid_lft forever preferred_lft forever

3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000

    link/ether 52:54:00:af:09:ea brd ff:ff:ff:ff:ff:ff

    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

       valid_lft forever preferred_lft forever

4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000

    link/ether 52:54:00:af:09:ea brd ff:ff:ff:ff:ff:ff

[root@localhost dell]# 

 3. Set dynamic ip:

It's more verbose here: but it's more detailed, and it's better for Xiaobai to understand! !

3.1 Execute network card configuration commands

Execute the network card configuration command - press Enter to enter the configuration interface:

[root@localhost dell]# vim /etc/sysconfig/network-scripts/ifcfg-ens32

3.2 Switch to insert mode

After entering, the interface is as follows: first press the lowercase i key to switch to insert mode:

YPE="Ethernet"

PROXY_METHOD="none"

BROWSER_ONLY="no"

BOOTPROTO="dhcp"

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="ens32"

UUID="35e1237d-262e-45d6-a190-40806d0cd2a2"

DEVICE="ens32"

ONBOOT="yes"

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

"/etc/sysconfig/network-scripts/ifcfg-ens32" 15L, 310C

3.3 Enter the compilation state

When the lower left corner becomes inserted:

YPE="Ethernet"

PROXY_METHOD="none"

BROWSER_ONLY="no"

BOOTPROTO="dhcp"

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="ens32"

UUID="35e1237d-262e-45d6-a190-40806d0cd2a2"

DEVICE="ens32"

ONBOOT="yes"

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

~                                                                                                                              

-- INSERT-- 

3.4 Enter the configuration state

Double-click and press the Esc key to return to the state without characters:

YPE="Ethernet"

PROXY_METHOD="none"

BROWSER_ONLY="no"

BOOTPROTO="dhcp"

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="ens32"

UUID="35e1237d-262e-45d6-a190-40806d0cd2a2"

DEVICE="ens32"

ONBOOT="yes"

~   

3.5 Modify dynamic configuration content

Note:

ONBOOT=yes state is to turn on the network card to start automatically

yes means to load the network, no means not to load the network, it needs to be changed to yes state

BOOTPROTO=dhcp status (indicates that it is set to dynamic ip)

  1. TYPE="Ethernet"
  2. PROXY_METHOD="none"
  3. BROWSER_ONLY="no"
  4. BOOTPROTO="dhcp"
  5. DEFROUTE="yes"
  6. IPV4_FAILURE_FATAL="no"
  7. IPV6INIT="yes"
  8. IPV6_AUTOCONF="yes"
  9. IPV6_DEFROUTE="yes"
  10. IPV6_FAILURE_FATAL="no"
  11. IPV6_ADDR_GEN_MODE="stable-privacy"
  12. NAME="ens32"
  13. UUID="35e1237d-262e-45d6-a190-40806d0cd2a2"
  14. DEVICE="ens32"
  15. ONBOOT="yes"

3.6 Save and exit

Note: Finally: shift+colon, wq=save and exit

  1. TYPE="Ethernet"
  2. PROXY_METHOD="none"
  3. BROWSER_ONLY="no"
  4. BOOTPROTO="dhcp"
  5. DEFROUTE="yes"
  6. IPV4_FAILURE_FATAL="no"
  7. IPV6INIT="yes"
  8. IPV6_AUTOCONF="yes"
  9. IPV6_DEFROUTE="yes"
  10. IPV6_FAILURE_FATAL="no"
  11. IPV6_ADDR_GEN_MODE="stable-privacy"
  12. NAME="ens32"
  13. UUID="35e1237d-262e-45d6-a190-40806d0cd2a2"
  14. DEVICE="ens32"
  15. ONBOOT="yes"
  16. ~                                                                                                                              
  17. ~                                                                                                                              
  18. ~                                                                                                                              
  19. ~                                                                                                                              
  20. ~                                                                                                                              
  21. ~                                                                                                                              
  22. ~                                                                                                                              
  23. ~                                                                                                                              
  24. ~                                                                                                                              
  25. ~                                                                                                                              
  26. :wq 

3.7 Test network

Note: ping baidu.com as shown in the figure below means that the network can be connected! ! cat+c to pause! !

  1. [root@localhost dell]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
  2. [root@localhost dell]# ping baidu.com Note: ping baidu.com as shown in the figure below can connect to the network! !
  3. PING baidu.com (110.242.68.66) 56(84) bytes of data.
  4. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=50 time=42.0 ms
  5. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=50 time=41.8 ms
  6. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=50 time=41.7 ms
  7. 64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=4 ttl=50 time=41.7 ms
  8. ^C Note: cat+c to pause! !
  9. --- baidu.com ping statistics ---
  10. 4 packets transmitted, 4 received, 0% packet loss, time 3011ms
  11. rtt min/avg/max/mdev = 41.712/41.845/42.040/0.191 ms
  12. [root@localhost dell]# 

First try, thank you for pointing out what's wrong!

Guess you like

Origin blog.csdn.net/m0_58871083/article/details/127380141