CentOS 7 network configuration and centos Network Configuration
CentOS 7 was installed on a PC today, and the minimum installation mode was selected at that time. After the installation is complete, use ifconfig to check the local IP address (DHCP already exists in the LAN). An error is reported, the ifconfig command is not found.
[Root @ centos1 ~] # Ifconfig
-Bash: ifconfig: command not found
First, habitually enter echo $ PATH (view the current PATH environment variable, which is the same as the DOS path command. Note that commands in Linux are case sensitive). The result is as follows:
[Root @ centos1 ~] # Echo $ PATH
/Usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
According to the results shown above, the path for placing the system administrator Program/usr/sbin already exists, that is, the path for placing External commands. Use ls to directly view the/usr/sbin/directory, and do not see ifconfig. What is going on?
[Root @ centos1 ~] # Ls/usr/sbin/
I still don't have to worry about it. I can't find ifconfig again with the find command?
[Root @ centos1 ~] # Find/-name "ifconfig"
At this point, I had a bottom point. I should have replaced ifconfig with a command. If you perform a hundred-level query, the ifconfig command has been replaced by the ip command. Common Parameters of ip commands are listed below.
Ip [Option] operation object {link | addr | route ...}
# Ip link show # display Network Interface Information # Ip link set eth0 upi # enable Nic # Ip link set eth0 down # disable the NIC # Ip link set eth0 promisc on # enable mixed Nic Mode # Ip link set eth0 promisc offi # disable mixed Nic Mode # Ip link set eth0 txqueuelen 1200 # set the length of the NIC queue # Ip link set eth0 mtu 1400 # set the maximum transmission unit of the NIC # Ip addr show # display Nic IP address information # Ip addr add 192.168.0.1/24 dev eth0 # Set eth0 Nic ip address 192.168.0.1 # Ip addr del 192.168.0.1/24 dev eth0 # Delete the ip address of the eth0 Nic
# Ip route list # view route 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 a default route |
After entering the ip addr command, we found that the enp2s0 NIC (this enp2s0 is my Nic) has no ip address.
[Root @ centos1 ~] # Ip addr
Since there is no ip address, go to the/etc/sysconfig/network-scripts directory and check the NIC ip Address Configuration File Name.
[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-ippp ifup-plusb ifup-sit ifup-wireless
[Root @ centos1 ~] #
From the results, the configuration file name that saves the NIC ip information also changed from the previous ifcfg-eth0 to the ifcfg-enp2s0, Okay, since you give him such a name, then I will first use. Cat the ifcfg-enp2s0 first
[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
20174_failure_fatal = no
IPV6INIT = yes
IPV6_AUTOCONF = yes
Required 6_defroute = yes
IPV6_PEERDNS = yes
20176_peerroutes = yes
20176_failure_fatal = no
NAME = enp2s0
UUID = 5b0a7d76-1602-4e19-aee6-29f57618ca01
ONBOOT = no
As shown in the above configuration, although BOOTPROTO = dhcp, but ONBOOT = no, here we use vi to change ONBOOT = no to ONBOOT = yes, and then restart CentOS.
[Root @ centos1 ~] # Shutdown-r
After the restart is complete, enter the account and password to enter the command prompt operator and continue to use the ip addr to view the NIC information. The result is as follows:
[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
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
[Root @ centos1 ~] #
From the above results, we can see that the ip address allocated through DHCP is 172.8.1.200. Although it is a test machine, we should configure a fixed ip address for this machine to facilitate remote connection in the future.
Open the ifcfg-enp2s0 with vi, enter the following parameters, and then # annotate BOOTPROTO = dhcp.
IPADDR0 = 172.8.1.211
PREFIX0 = 24
GATEWAY0 = 172.8.1.1
DNS1 = 172.8.1.1
The complete parameters are as follows. Test other functions tomorrow.
[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
20174_failure_fatal = no
IPV6INIT = yes
IPV6_AUTOCONF = yes
Required 6_defroute = yes
IPV6_PEERDNS = yes
20176_peerroutes = yes
20176_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
[Root @ centos1 ~] #
To be continued ......