CentOS 7 网络设置
最小化安装的CentOS没有图形化配置工具,可以通过文件进行配置。
[root@test ~]# cd /etc/sysconfig/network-scripts/ [root@test network-scripts]# ll total 232 -rw-r--r--. 1 root root 410 Jun 4 11:30 ifcfg-eno1 -rw-r--r--. 1 root root 254 Aug 19 2019 ifcfg-lo lrwxrwxrwx. 1 root root 24 Jun 4 11:26 ifdown -> ../../../usr/sbin/ifdown -rwxr-xr-x. 1 root root 654 Aug 19 2019 ifdown-bnep -rwxr-xr-x. 1 root root 6532 Aug 19 2019 ifdown-eth -rwxr-xr-x. 1 root root 781 Aug 19 2019 ifdown-ippp -rwxr-xr-x. 1 root root 4540 Aug 19 2019 ifdown-ipv6 lrwxrwxrwx. 1 root root 11 Jun 4 11:26 ifdown-isdn -> ifdown-ippp -rwxr-xr-x. 1 root root 2130 Aug 19 2019 ifdown-post -rwxr-xr-x. 1 root root 1068 Aug 19 2019 ifdown-ppp -rwxr-xr-x. 1 root root 870 Aug 19 2019 ifdown-routes -rwxr-xr-x. 1 root root 1456 Aug 19 2019 ifdown-sit -rwxr-xr-x. 1 root root 1621 Dec 9 2018 ifdown-Team -rwxr-xr-x. 1 root root 1556 Dec 9 2018 ifdown-TeamPort -rwxr-xr-x. 1 root root 1462 Aug 19 2019 ifdown-tunnel lrwxrwxrwx. 1 root root 22 Jun 4 11:26 ifup -> ../../../usr/sbin/ifup -rwxr-xr-x. 1 root root 12415 Aug 19 2019 ifup-aliases -rwxr-xr-x. 1 root root 910 Aug 19 2019 ifup-bnep -rwxr-xr-x. 1 root root 13574 Aug 19 2019 ifup-eth -rwxr-xr-x. 1 root root 12075 Aug 19 2019 ifup-ippp -rwxr-xr-x. 1 root root 11893 Aug 19 2019 ifup-ipv6 lrwxrwxrwx. 1 root root 9 Jun 4 11:26 ifup-isdn -> ifup-ippp -rwxr-xr-x. 1 root root 650 Aug 19 2019 ifup-plip -rwxr-xr-x. 1 root root 1064 Aug 19 2019 ifup-plusb -rwxr-xr-x. 1 root root 4997 Aug 19 2019 ifup-post -rwxr-xr-x. 1 root root 4154 Aug 19 2019 ifup-ppp -rwxr-xr-x. 1 root root 2001 Aug 19 2019 ifup-routes -rwxr-xr-x. 1 root root 3303 Aug 19 2019 ifup-sit -rwxr-xr-x. 1 root root 1755 Dec 9 2018 ifup-Team -rwxr-xr-x. 1 root root 1876 Dec 9 2018 ifup-TeamPort -rwxr-xr-x. 1 root root 2780 Aug 19 2019 ifup-tunnel -rwxr-xr-x. 1 root root 1836 Aug 19 2019 ifup-wireless -rwxr-xr-x. 1 root root 5419 Aug 19 2019 init.ipv6-global -rw-r--r--. 1 root root 20678 Aug 19 2019 network-functions -rw-r--r--. 1 root root 31027 Aug 19 2019 network-functions-ipv6 [root@test network-scripts]# vi ifcfg-eno1 #修改网卡配置 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="eno1" UUID="7ae940d1-9bfb-4890-8024-49a10c73cc1e" DEVICE="eno1" ONBOOT="yes" IPADDR="192.168.11.124" PREFIX="24" GATEWAY="192.168.11.254" DNS1="114.114.114.114" IPV6_PRIVACY="no"
[root@test network-scripts]# systemctl restart network #重启网络
[root@test network-scripts]# ip addr #查看网卡信息
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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
qdisc pfifo_fast state UP group default qlen 1000
link/ether 44:37:e6:a3:0f:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.11.124/24 brd 192.168.11.255 scope global noprefixroute eno1
valid_lft forever preferred_lft forever
inet6 fe80::7227:92f0:e0f7:20c3/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@test 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 Tue 2021-06-15 08:46:48 CST; 7h ago
Docs: man:systemd-sysv-generator(8)
Process: 895 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
Jun 15 08:46:47 test systemd[1]: Starting LSB: Bring up/down networking...
Jun 15 08:46:48 test network[895]: Bringing up loopback interface: [ OK ]
Jun 15 08:46:48 test network[895]: Bringing up interface eno1: [ OK ]
Jun 15 08:46:48 test systemd[1]: Started LSB: Bring up/down networking.
[root@test network-scripts]# systemctl list-unit-files |grep -E "enabled|static"
#查看当前启用的服务
auditd.service enabled
autovt@.service enabled
chronyd.service enabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
docker.service enabled
firewalld.service enabled
getty@.service enabled
irqbalance.service enabled
lvm2-monitor.service enabled
microcode.service enabled
NetworkManager-dispatcher.service enabled
NetworkManager-wait-online.service enabled
NetworkManager.service enabled
postfix.service enabled
rhel-autorelabel-mark.service enabled
rhel-autorelabel.service enabled
rhel-configure.service enabled
rhel-dmesg.service enabled
rhel-domainname.service enabled
rhel-import-state.service enabled
rhel-loadmodules.service enabled
rhel-readonly.service enabled
rsyslog.service enabled
smb.service enabled
sshd.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
dm-event.socket enabled
lvm2-lvmetad.socket enabled
lvm2-lvmpolld.socket enabled
default.target enabled
multi-user.target enabled
network-online.target static
network-pre.target static
network.target static
remote-fs.target enabled
runlevel2.target enabled
runlevel3.target enabled
runlevel4.target enabled