CentOS7 Network Configuration

Source: Internet
Author: User

CentOS7 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 Nic # ip link set eth0 promisc on # enable Nic hybrid mode # ip link set eth0 promisc offi # disable the mixed Nic mode # ip link set eth0 txqueuelen 1200 # set the NIC queue length # ip link set eth0 mtu 1400 # set the maximum Nic transmission unit # 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 eth0 Nic ip address # 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, 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 routing

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-globalifcfg-lo ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-isdn ifup-ppp ifup-TeamPort network-functionsifdown ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel network-functions-ipv6ifdown-bnep ifdown-isdn ifdown-sit ifup 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-enp2s0HWADDR=00:E0:69:01:6A:96TYPE=EthernetBOOTPROTO=dhcpDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noNAME=enp2s0UUID=5b0a7d76-1602-4e19-aee6-29f57618ca01ONBOOT=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 add1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:e0:69:01:6a:96 brd ff:ff:ff:ff:ff:ffinet 172.8.1.200/24 brd 172.8.1.255 scope global enp2s0valid_lft forever preferred_lft foreverinet6 fe80::2e0:69ff:fe01:6a96/64 scope linkvalid_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.211PREFIX0=24GATEWAY0=172.8.1.1DNS1=172.8.1.1

The complete parameters are as follows. Test other functions tomorrow.

[root@centos1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp2s0HWADDR=00:E0:69:01:6A:96TYPE=Ethernet#BOOTPROTO=dhcpDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noNAME=enp2s0UUID=5b0a7d76-1602-4e19-aee6-29f57618ca01ONBOOT=yesIPADDR0=172.8.1.211PREFIX0=24GATEWAY0=172.8.1.1DNS1=172.8.1.1[root@centos1 ~]#

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.