CentOS 7 Network Configuration

 

 Today I installed CentOS 7 on a PC. At that time, I chose the minimal installation mode. Immediately after the installation was completed, I used ifconfig to check the ip address of the machine (the local area network already has DHCP), and found that an error was reported, indicating that the ifconfig command was not found.


[root@centos1 ~]#  ifconfig

-bash: ifconfig: command not found

First, habitually enter echo $PATH (check the current PATH environment variable, the same function as the DOS path command, note that the commands in the Linux system are size-sensitive written), the display result is as follows:

[root@centos1 ~]#  echo $PATH

/usr/local/sbin:/usr/local/bin: /usr/sbin :/usr/bin:/root/bin

Display the result from above Look, the path /usr/sbin where the system management program is placed already exists, which is the path where the external command is placed. Check the /usr/sbin/ directory directly with ls , but I don't see ifconfig , what's going on? [root@centos1 ~]#  ls /usr/sbin/ I still don't give up, and I can't find ifconfig with the find command ? [root@centos1 ~]#  find / -name "ifconfig" At this time, I have a bottom line, it should be Replace ifconfig with a command







. I checked on Baidu, and sure enough, the ip command has been used instead of the ifconfig command. The common parameters of the ip command are listed below .

 

ip [options] Operation object {link|addr|route...}

# ip link show # Display network interface information
# ip link set eth0 upi # Turn on the network card
# ip link set eth0 down # Turn off the network card
# ip link set eth0 promisc on # Enable the mixed mode of the network card
# ip link set eth0 promisc offi # Turn off the mixed mode of the network card
# ip link set eth0 txqueuelen 1200 # Set the queue length of the network card
# ip link set eth0 mtu 1400 # Set the maximum transmission unit of the network card
# ip addr show # Display network card IP information
# ip addr add 192.168.0.1/24 dev eth0 # Set the eth0 network card IP address 192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # Delete the eth0 network card IP address

# ip route list # View routing information
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # Set the gateway of the 192.168.4.0 network segment to 192.168.0.254, and the data goes through the eth0 interface
# ip route add default via 192.168.0.254 dev eth0 # Set the default gateway to 192.168.0.254
# ip route del 192.168.4.0/24 # Delete the gateway of the 192.168.4.0 network segment
# ip route del default # Delete the default route


输入ip addr命令后,发现enp2s0网卡(这个enp2s0是我这里的网卡)没有ip地址。

[root@centos1 ~]# ip addr

既然没有ip地址,那直接去/etc/sysconfig/network-scripts目录中看一下的网卡ip信息的配置文件名吧。

[root@centos1 ~]# ls /etc/sysconfig/network-scripts/
ifcfg-enp2s0  ifdown-eth   ifdown-post    ifdown-Team      ifup-aliases  ifup-ipv6   ifup-post    ifup-Team      init.ipv6-global
ifcfg-lo      ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep     ifup-isdn   ifup-ppp     ifup-TeamPort  network-functions
ifdown        ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth      ifup-plip   ifup-routes  ifup-tunnel    network-functions-ipv6
ifdown-bnep   ifdown-isdn  ifdown-sit     ifup             ifup-ippp     ifup-plusb  ifup-sit     ifup-wireless


从结果看,之前保存网卡ip信息的配置文件名也由以前的ifcfg-eth0变成了ifcfg-enp2s0,好吧,既然你给他命这么个名,那我就先用着。先cat一下ifcfg-enp2s0
[root@centos1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp2s0
HWADDR=00:E0:69:01:6A:96
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp2s0
UUID=5b0a7d76-1602-4e19-aee6-29f57618ca01
ONBOOT=no

从上面的配置中有看到虽然BOOTPROTO=dhcp,但是ONBOOT=no,这里用viONBOOT=no改成ONBOOT=yes,然后重启CentOS。

[root@centos1 ~]# shutdown -r

重启完成后输入帐号和密码进入命令提示操作符继续用ip addr查看网卡信息。结果如下:
[root@centos1 ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:e0:69:01:6a:96 brd ff:ff:ff:ff:ff:ff
    inet 172.8.1.200/24 brd 172.8.1.255 scope global enp2s0
       valid_lft forever preferred_lft forever
    inet6 fe80::2e0:69ff:fe01:6a96/64 scope link
       valid_lft forever preferred_lft forever

从上面结果看到,通过DHCP分配到的ip地址是172.8.1.200,虽然是测试机,但为了便于今后的远程连接,我们还是给这台机配置一个固定ip吧。

vi打开ifcfg-enp2s0,输入以下参数,再用#BOOTPROTO=dhcp注释。
IPADDR0=172.8.1.211
PREFIX0=24
GATEWAY0=172.8.1.1
DNS1=172.8.1.1

完整参数如下,好了,网络配通了。明天继续其它功能测试。
[root@centos1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp2s0
HWADDR=00:E0:69:01:6A:96
TYPE=Ethernet
#BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp2s0
UUID=5b0a7d76-1602-4e19-aee6-29f57618ca01
ONBOOT=yes
IPADDR0=172.8.1.211
PREFIX0=24
GATEWAY0=172.8.1.1
DNS1=172.8.1.1

 

当联上互联网后,我们可以用yum install net-tools安装net-tools组件,将ifconfig命令找回来。有了互联网一切都好办了。

[root@centos1 ~]#yum install net-tools

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608659&siteId=291194637