Today in a PC installed CentOS 7, then chose the minimum installation mode, the installation is completed immediately with ifconfig view the IP address of the computer (LAN already has DHCP), found an error, prompted Ifconfig command did not find.
[Root@centos1 ~]# ifconfig
-bash:ifconfig:command not found
First of all, the habitual input echo $PATH (see the current PATH environment variable, the same function as the DOS Path command, noting that the commands in the Linux system are case-sensitive), the results are as follows:
[Root@centos1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
From the results shown above, the path to place the system Management program/usr/sbin already exists, which is the path to the external command. Directly with LS to view/usr/sbin/directory, also did not see Ifconfig, how to return?
[Root@centos1 ~]# ls/usr/sbin/
I still do not give up, and then use Find command also found no ifconfig?
[Root@centos1 ~]# Find/-name "Ifconfig"
At this time the heart bottom, should be with an order instead of ifconfig. Baidu a check, sure enough, has used IP commands instead of ifconfig command. The common parameters for IP commands are listed below.
IP [Options] Action object {Link|addr|route ...}
# IP link Show # Display network interface information
# IP Link set eth0 UPI # Open Network Card
# IP Link set eth0 down # turn off the NIC
# IP Link set eth0 promisc on # Open Network card blending mode
# IP Link Set eth0 promisc offi # Turn off the mixed mode of the NIC
# IP Link Set eth0 txqueuelen 1200 # Set network card queue Length
# IP Link Set eth0 MTU 1400 # Set network card maximum transmission unit
# IP Addr Show # Display network card IP information
# ip addr Add 192.168.0.1/24 dev eth0 # set eth0 network card IP address 192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # remove 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 192.168.4.0 network segment to 192.168.0.254, data go eth0 interface
# IP route add default via 192.168.0.254 dev eth0 # Set default gateway to 192.168.0.254
# ip Route del 192.168.4.0/24 # Remove gateway to 192.168.4.0 network segment
# IP route del Default # Delete the defaults route
After entering the IP addr command, I found that the ENP2S0 network card (this enp2s0 is My network card) does not have an IP address.
[Root@centos1 ~]# IP Addr
Since there is no IP address, then go directly to the/etc/sysconfig/network-scripts directory to see the network card IP information configuration file name bar.
[Root@centos1 ~]# ls/etc/sysconfig/network-scripts/
ifcfg-enp2s0 ifdown-eth ifdown-post ifup-aliases Ifup-ipv6 ifup-post ifup-team init.ipv6-global Ifcfg-lo IFDOWN-PPP ifdown-teamport ifup-bnep ifup-isdn ifup-ppp ifup-teamport
ifdown ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-plip Ifup-tunnel Network-functions-ipv6
ifdown-bnep ifdown-isdn ifdown-sit ifup Ifup-plusb ifup-sit ifup-wireless
From the results, the previous Save the network card IP information configuration file name from the previous ifcfg-eth0 into the IFCFG-ENP2S0, well, since you give him a name, then I will use first. First 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
From the above configuration has seen although bootproto=dhcp, but onboot=no, here with VI will onboot=no to Onboot=yes, and then restart CentOS.
[Root@centos1 ~]# Shutdown-r
Enter the account number and password after reboot to enter the command prompt operator to continue using IP addr to view the network card information. The results are as follows:
[ROOT@CENTOS1 ~]# IP Add
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN
Link/loopback 0 0:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 scopes host lo valid_lft forever preferred_lft forever<
C5/>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
From the results above, the IP address assigned through 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.
With VI open IFCFG-ENP2S0, 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, well, the network is equipped. Continue with other functional tests 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
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=
gateway0=172.8.1.1
dns1=172.8.1.1
When we connect to the Internet, we can use Yum install Net-tools to install the Net-tools component and get the Ifconfig command back. With the internet everything is good to do.
[ROOT@CENTOS1 ~] #yum Install Net-tools
=======================================
Linux start and turn off the network card command
Linux command 1:ifup, Ifdown:
Real-time manual modification of some network interface parameters, you can use ifconfig to achieve, if you want to directly to the configuration file, that is, in the/etc/sysconfig/network-scripts inside the IFCFG-ETHX and other files set parameters to start, It has to be done through Ifdown or ifup.
[Root@linux ~]# ifup {interface}
[Root@linux ~]# ifdown {interface}
[Root@linux ~]# ifup-eth0
Ifup and Ifdown are just too easy. These two programs are actually script, it will go directly to the/etc/sysconfig/network-scripts directory to search for the corresponding configuration file, such as Ifup eth0, it will find ifcfg-eth0 the contents of the file, and then set. For Ifcfg-eth0 settings, refer to the previous chapter for instructions on connecting to the Internet.
However, since these two programs are primarily the search settings file (IFCFG-ETHX) for startup and shutdown, make sure that the IFCFG-ETHX exists in the correct directory before using it, or it will fail to start. In addition, if you set or modify the network interface with Ifconfig eth0, you can no longer shut down in Ifdown eth0 mode. Because Ifdown will analyze compare current network parameter and ifcfg-eth0 whether match, do not match, will abandon this operation. Therefore, after the use of ifconfig modified, should be ifconfig eth0 down to be able to close the interface.
How to make Linux network card boot automatically
The command to activate the network card is: ifconfig eth0 up you know the command, you do a script, put on the startup project on it.
Modify the NIC configuration file by editing the network card profile to save it under the/etc/sysconfig/network-scripts directory.
The first card file is Ifcfg-eth0
The second NIC file is Ifcfg-eth1
And so on, if you have a piece, then you type in the command
[Root@linux ~]# Vi/etc/sysconfig/network-scripts/ifcfg-eth0
After opening, change the Onboot=no to Onboot=yes, (if not, add Onboot=yes manually): Wq save exit, restart the service.
echo "Onboot=yes" >>/etc/sysconfig/network-script/ifcfg-eth0
Add Onboot=yes to/etc/sysconfig/network-scripts to set up the network to boot automatically
Linux Command 2:/etc/init.d/network Restart and service network restart
[Root@centos2 ~]#/etc/init.d/network Restart
The
is shutting down the interface eth1: [OK]
Turn off loopback interface: [OK]
Pop-up loopback interface: [OK]
Pop-up interface eth1:determining if IP address 10.0.0.168 is already in use for device eth1 ...
[OK]
[root@centos2 ~]# service Network restart
The
is shutting down the interface eth1: [OK]
Turn off loopback interface: [OK]
Pop-up loopback interface: [OK]
Pop-up interface eth1:determining if IP address 10.0.0.168 is already in use for device eth1 ...
[OK]
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.