NetworkManager VS network

After centos7 modifies the ifcfg-ens33 file (mainly configuring ip, gateway and other information), how does the network card start correctly?

  • Modify /etc/sysconfig/network-scripts/ifcfg-ens33 and add configuration.

It is recommended to back up before modifying.

[root@centos79original network-scripts]# diff /soft/ifcfg-bak/ifcfg-ens33_bak20230914 ifcfg-ens33
4c4
<BOOTPROTO=dhcp
---
>BOOTPROTO=static
15a16,19
> IDADDR=192.168.101.197
> NETMASK=255.255.254.0
>GATEWAY=192.168.100.1
> HWADDR=00:0C:29:33:A3:F6

Revise:

BOOTPROTO=static;

Add to:

IDADDR=192.168.101.197
NETMASK=255.255.254.0
GATEWAY=192.168.100.1
HWADDR=00:0C:29:33:A3:F6

The final guarantee file cannot contain configuration item errors, otherwise it will affect subsequent startup. After modification:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
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=ens33
UUID=ba80c1e7-3345-4543-8ed0-9681283ba08b
DEVICE=ens33
ONBOOT=yes
IDADDR=192.168.101.197
NETMASK=255.255.254.0
GATEWAY=192.168.100.1
HWADDR=01:0C:29:33:A3:F6
  • Close network service
systemctl stop network
  • Restart the NetworkManager service
# Restart
systemctl restart NetworkManager

# Check status (guarantee successful startup)
systemctl status NetworkManager

[root@centos79original network-scripts]# systemctl status NetworkManager
● NetworkManager.service – Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Thursday 2023-09-14 11:24:59 CST; 4s ago
Docs: man:NetworkManager(8)
Main PID: 7032 (NetworkManager)
Tasks: 5
Memory: 4.3M
CGroup: /system.slice/NetworkManager.service
├─7032 /usr/sbin/NetworkManager –no-daemon
└─7073 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens33.pid -lf /var/lib/NetworkManager/dhclient-453addc5-ef8b- 3277-b061-356abfd2e0ab-e…

September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6148] device (ens33): state change: ip-config -> ip-check (reason ‘none’, sys-iface-state: ‘managed’)
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6152] device (ens33): state change: ip-check -> secondaries (reason ‘none’, sys-iface-state: ‘ managed’)
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6153] device (ens33): state change: secondaries -> activated (reason ‘none’, sys-iface-state: ‘managed\ ‘)
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6175] manager: NetworkManager state is now CONNECTED_LOCAL
September 14 11:25:00 centos79original dhclient[7073]: bound to 192.168.101.197 — renewal in 32933 seconds.
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6261] manager: NetworkManager state is now CONNECTED_SITE
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6262] policy: set ‘Wired connection 1’ (ens33) as default for IPv4 routing and DNS
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6290] device (ens33): Activation: successful, device activated.
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6295] manager: NetworkManager state is now CONNECTED_GLOBAL
September 14 11:25:00 centos79original NetworkManager[7032]: [1694661900.6299] manager: startup complete
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos79original network-scripts]#

#View network card status
nmcli device status ens33

[root@centos79original network-scripts]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected Wired connection 1
docker0 bridge unmanaged —
virbr0 bridge unmanaged —
lo loopback unmanaged —
virbr0-nic tun unmanaged —
[root@centos79original network-scripts]#

  • Start network service
systemctl start network

# Check service status
systemctl status network

[root@centos79original network-scripts]# systemctl start network
[root@centos79original network-scripts]#
[root@centos79original network-scripts]# systemctl status network
● network.service – LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: active (exited) since Thursday 2023-09-14 11:25:55 CST; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 6784 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
Process: 7319 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

September 14 11:25:55 centos79original systemd[1]: Starting LSB: Bring up/down networking…
September 14 11:25:55 centos79original network[7319]: Bringing up loopback interface: [ OK ]
September 14 11:25:55 centos79original network[7319]: Bringing up interface ens33: [ OK ]
September 14 11:25:55 centos79original systemd[1]: Started LSB: Bring up/down networking.
[root@centos79original network-scripts]#

  • Network problem solving:

[root@centos79original network-scripts]# ping www.baidu.com
PING www.a.shifen.com (180.101.50.242) 56(84) bytes of data.
64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=1 ttl=52 time=6.29 ms
64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=2 ttl=52 time=2.71 ms
64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=3 ttl=52 time=2.73 ms
64 bytes from 180.101.50.242 (180.101.50.242): icmp_seq=4 ttl=52 time=2.49 ms
^C
— www.a.shifen.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 2.497/3.559/6.296/1.584 ms
[root@centos79original network-scripts]#