Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

4.1.3 Configure network card information


May 23, 2021 That's what Linux should learn



Whether the IP address of the network card is configured correctly is a prerequisite for whether the two servers can communicate with each other. I n a Linux system, everything is a file, so the job of configuring a network service is actually editing the network card profile, so this little task not only helps you practice using the Vim editor, but also provides a solid foundation for you to learn about the various service configurations in Linux later. When you study this book carefully, you will be particularly accomplished, because the foundation of the first part of this book is very solid, and the back content has an almost consistent network card IP address and operating environment, so that you can devote yourself to the study of various service programs, without having to worry about the system environment.

If you have some operations experience or are familiar with early Linux systems, you will encounter some difficult differences when learning this book. I n RHEL 5, RHEL 6, the prefix of the network card profile is eth, the first network card is eth0, the second network card is eth1, and so on. In RHEL 7, the prefix of the network card profile starts with ifcfg, and the name of the network card together forms the name of the network card profile, such as ifcfg-eno16777736;

Now there is a network card device named ifcfg-eno16777736, which we configure to boot and start, and the IP address, subnet, gateway and other information is manually specified, the steps should be as follows.

Step 1: First switch to /etc/sysconfig/network-scripts directory (the profile that holds the network card).

Step 2: Use the Vim editor to modify the network card file ifcfg-eno16777736, write the configuration parameters below item by item and save the exit. Because the hardware and architecture of each device are different, ask the reader to confirm the default name of their network card using the ifconfig command.

Device type: TYPE-Ethernet

Address allocation mode: BOOTPROTO-static

Network card name: NAME-eno16777736

Whether to start: ONBOOT=yes

IP Address: IPADDR: 192.168.10.10

Subnet mask: NETMASK s 255.255.255.0

Gateway address: GATEWAY s 192.168.10.1

DNS Address: DNS1 s 192.168.10.1

Step 3: Restart the network service and test whether the network is connected or not.

Go to the directory where the network card profile is located, and then edit the network card profile to fill in the following information:

[root@linuxprobe ~]# cd /etc/sysconfig/network-scripts/ [root@linuxprobe network-scripts]# vim ifcfg-eno16777736 TYPE=Ethernet BOOTPROTO=static NAME=eno16777736 ONBOOT=yes IPADDR=192.168.10.10 NETMASK=255.255.255.0 GATEWAY=192.168.10.1 DNS1=192.168.10.1

Execute the command to restart the network card device (under normal circumstances there will be no prompt message), and then test the network's connectivity with the ping command. Because the ping command does not terminate automatically in a Linux system, the Ctrl-c key needs to be pressed manually to force the process to end.

[root@linuxprobe network-scripts]# systemctl restart network [root@linuxprobe network-scripts]# ping 192.168.10.10 PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data. 6 4 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.081 ms 64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.083 ms 64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.059 ms 64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.097 ms ^C --- 192.168.10.10 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.059/0.080/0.097/0.013 ms