Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize CentOS 7 Network configuration

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize CentOS 7 network configuration". In daily operation, I believe many people have doubts about how to realize CentOS 7 network configuration. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to realize CentOS 7 network configuration". Next, please follow the editor to study!

[root@centos1 ~] # ifconfig

-bash: ifconfig: command not found

First of all, enter echo $PATH habitually (check the current PATH environment variable, which has the same function as the path command of DOS, and note that the commands in the Linux system are case-sensitive), and the result is 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 / usr/sbin where the hypervisor is placed already exists, which is the path where external commands are placed. Check the / usr/sbin/ directory directly with ls, but you don't see ifconfig. What's going on?

[root@centos1 ~] # ls / usr/sbin/

I still don't give up. I can't find ifconfig with the find command.

[root@centos1 ~] # find /-name "ifconfig"

Now that I have some confidence in my mind, I should have replaced ifconfig with some command. Hundreds of degrees check, sure enough, the ip command has been used instead of the ifconfig command. The common parameters of the ip command are listed below.

The code is as follows:

Ip [option] Operand {link | addr | route...}

# ip link show # display network interface information

# ip link set eth0 upi # enable the network card

# ip link set eth0 down # turn off the Nic

# ip link set eth0 promisc on # enable mixed mode of Nic

# ip link set eth0 promisc offi # turn off mixed mode of Nic

# ip link set eth0 txqueuelen 1200 # set the queue length of the Nic

# ip link set eth0 mtu 1400 # set the maximum transmission unit of the network card

# ip addr show # display the IP information of the network card

# ip addr add 192.168.0.1 dev eth0 24 dev eth0 # set the IP address of the eth0 network card 192.168.0.1

# ip addr del 192.168.0.1 dev eth0 24 dev eth0 # Delete the IP address of the eth0 Nic

# ip route list # View routing information

# ip route add 192.168.4.0 via 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.0Universe 24 # Delete the gateway of the 192.168.4.0 network segment

# ip route del default # Delete the default route

After entering the ip addr command, I found that the enp2s0 network card (this enp2s0 is my network card here) does not have an ip address.

[root@centos1 ~] # ip addr

Since there is no ip address, go directly to the / etc/sysconfig/network-scripts directory to take a look at the configuration file name of the network card ip information.

[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

[root@centos1 ~] #

As a result, the name of the configuration file that saved the ip information of the network card has also changed from the previous ifcfg-eth0 to ifcfg-enp2s0. Well, since you have given him such a name, I will use it first. Cat ifcfg-enp2s0 first.

[root@centos1 ~] # cat / etc/sysconfig/network-scripts/ifcfg-enp2s0

The code is as follows:

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 configuration above, you can see that although BOOTPROTO=dhcp is ONBOOT=no, here you use vi to change ONBOOT=no to ONBOOT=yes, and then restart CentOS.

[root@centos1 ~] # shutdown-r

After the restart, enter the account number and password to enter the command prompt operator to continue to use ip addr to view the network card information. The results are as follows:

[root@centos1 ~] # ip add

1: lo: 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: 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

[root@centos1 ~] #

As you can see from the above results, the ip address assigned through DHCP is 172.8.1.200. Although it is a test machine, let's configure this machine with a fixed ip for future remote connections.

Open ifcfg-enp2s0 with vi, enter the following parameters, and comment the BOOTPROTO=dhcp with #.

The code is as follows:

IPADDR0=172.8.1.211

PREFIX0=24

GATEWAY0=172.8.1.1

DNS1=172.8.1.1

The complete parameters are as follows. All right, the network is connected. Other functional tests will continue tomorrow.

[root@centos1 ~] # cat / etc/sysconfig/network-scripts/ifcfg-enp2s0

The code is as follows:

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

[root@centos1 ~] #

At this point, the study on "how to implement CentOS 7 network configuration" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report