CentOS 7 Network configuration

Source: Internet
Author: User

Today on a PC installed CentOS 7, at that time chose the minimum installation mode, the installation is completed immediately after the Ifconfig to view the IP address of the machine (LAN already has DHCP), found an error, prompted Ifconfig command did not find.

[Email protected] ~]#ifconfig

-bash:ifconfig:command not found

First, the habitual input echo $PATH (view the current PATH environment variable, the same function as the DOS Path command, note that the commands in the Linux system are case-sensitive), the results are as follows:

[Email protected] ~]#Echo $PATH

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

From the results shown above, the placement of the hypervisor path/usr/sbin already exists, that is, the path of the external command. Directly withlsView/usr/sbin/Catalogue, nor see Ifconfig, what's going on?

[Email protected] ~]#ls/usr/sbin/

I still do not forget, and then use the Find command also found Ifconfig?

[Email protected] ~]#Find/-name "Ifconfig"

At this point in the heart, should be a command to replace the ifconfig. On Baidu a check, sure enough, has been usedIPCommand insteadifconfigThe order. Listed belowIPCommand common parameters.


IP [Options] Action object {Link|addr|route ...}

# IP Link Show # Displays network interface information
# IP Link set eth0 UPI # Open Nic
# IP Link set eth0 down # close NIC
# IP Link set eth0 promisc on # open NIC Mixed mode
# IP Link Set eth0 promisc offi # Turn off the network card mix mode
# IP Link Set eth0 txqueuelen 1200 # set NIC Queue Length
# IP Link Set eth0 MTU 1400 # set NIC Maximum transmission unit
# IP Addr Show # Displays network card IP 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 # remove eth0 NIC 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 for 192.168.4.0 segment to 192.168.0.254, Data walk eth0 interface
# IP route add default via 192.168.0.254 Dev Eth0 # to set the defaults gateway to 192.168.0.254
# ip Route del 192.168.4.0/24 # Remove gateway for 192.168.4.0 network segment
# IP Route del Default # to delete the defaults route


After you enter the IP addr command, you findEnp2s0Network Card (thisEnp2s0Is my network card here) no IP address.

[Email protected] ~]#IP Addr

Since there is no IP address, go directly to the/etc/sysconfig/network-scripts directory to see the network card IP information configuration file name it.

[Email protected] ~]#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-f Unctions
Ifdown Ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip ifup-routes ifup-tunnel network-f Unctions-ipv6
IFDOWN-BNEP ifdown-isdn ifdown-sit ifup ifup-ippp ifup-plusb ifup-sit ifup-wireless

[Email protected] ~]#

From the results, the configuration file name of the previously saved NIC IP information is also changed from the previous ifcfg-eth0 to Ifcfg-enp2s0, well, since you gave him such a name, I'll use it first. Cat First Ifcfg-enp2s0
[Email protected] ~]#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

From the above configuration to see although bootproto=dhcp, but onboot=no, here with VI will onboot=no change to Onboot=yes, and then restart CentOS.

[Email protected] ~]#Shutdown-r

After reboot, enter account number and password enter the command prompt operator to continue to view network card information with IP addr. The results are as follows:
[Email protected] ~]#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 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

[Email protected] ~]#

As seen from the above results, the IP address assigned to by DHCP is 172.8.1.200, although it is a test machine, but in order to facilitate future remote connection, we still configure a fixed IP for this machine.

Open Ifcfg-enp2s0 with VI, enter the following parameters, and then use # to BOOTPROTO=DHCP comments.
ipaddr0=172.8.1.211
Prefix0=24
gateway0=172.8.1.1
dns1=172.8.1.1

The complete parameters are as follows, OK, the network is well-equipped. Continue with other functional tests tomorrow.
[Email protected] ~]#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

[Email protected] ~]#

Cond......

CentOS 7 Network configuration

Related Article

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.