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

Network configuration under Linux-CentOS 6.x

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

Share

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

Network configuration under Linux-CentOS 6.x

Text keywords: Linux, CentOS, network service, eth0, Nic configuration item

First, view network information

Usually when we check whether the network of this machine is normal, the main thing we need to know is whether the network card is working properly and what the relevant network information (IP address, broadcast address, subnet mask, etc.) is. In addition, we need to test whether the current machine is connected to the Internet, or whether it can communicate properly with the gateway.

1. Ifconfig

Ifconfig is one of the most commonly used tools to view and set up network cards.

Use the ifconfig command directly: list all currently enabled Nic information

Use ifconfig and network card name: view the information of a network card specifically

2. Ping

Using the ping command can be used to test the connectivity of the network, and it is convenient for us to troubleshoot problems. Usually, we will first check the connectivity of the gateway, followed by an address of the external network, such as Baidu.

Check connectivity to the gateway

Check connectivity to an address of the public network

Second, modify the network configuration. Network card configuration item DEVICE: device name TYPE: network type (Ethernet, etc.) ONBOOT: whether to automatically enable (yes/no) HWADDR:MAC address (physical address) BOOTPROTO: network card to obtain configuration (dhcp/static/none/ other) IPADDR:IP address NETMASK: subnet mask GATEWAY: gateway address BROADCAST: broadcast address DNS:DNS server address NAME: network card name USERCTL: whether ordinary users can control (yes/no) 2. Take effect temporarily

Use the ifconfig command to temporarily modify the configuration of the network card until the next network card restart, or until the computer restarts.

Temporarily modify IP address

Temporarily bind multiple IP addresses

3. Take effect permanently

Using the setup tool to modify the network configuration, or directly modifying the network card configuration file can make the configuration take effect permanently, and you need to restart manually when the first modification is completed.

Setup tool: use root users to enter the setup tool for network configuration

You can set the network card and DNS, it is important to note that the DNS setting in the network card configuration file has a higher priority, if you want to configure the same DNS server address for all network cards, then you should make sure that the DNS configuration does not appear in the network card configuration file, and then specify the DNS server address in the DNS configuration.

Here, you can activate or close the network card, or remove the network card configuration. Select the network card and enter directly to enter the configuration.

The part that displays the asterisk indicates that it is turned on and enabled, and toggles through the space. You can manually modify configurations such as IP address when dhcp is off, otherwise it is locked, and save and exit after the modification is completed.

The DNS configuration in the Nic configuration file is written to the DNS parsing configuration.

Modification of configuration file: / etc/sysconfig/network-scripts/ifcfg-eth0

The way to use the setup tool to modify is essentially to modify the configuration file of the network card. It is important to note that if you are configuring the relevant information manually, be sure to use the correct subnet mask and broadcast address, and the IP address must be on the same network segment as the gateway. For VMware virtualization software: vmnet0 (bridging mode), vmnet1 (host mode only), vmnet8 (NAT mode) have different gateways.

Bridging mode: if the virtual machine is treated as a real machine and directly connected to the network where the host is located, and other machines in the LAN can also access the virtual machine, the gateway address should be the same as the host.

Host-only mode: if the virtual machine can only communicate with the host and cannot connect to the external network (unless proxy forwarding is used), the gateway address should be the same as the Nic address of the vmnet1 in the host, usually xxx.xxx.xxx.1, and the virtual machine can use this address to communicate with the host.

NAT mode: if the virtual machine can share the network with the host and can also communicate with the host, the gateway address is assigned as xxx.xxx.xxx.2 by default, and the network card address of the vmnet8 in the host is xxx.xxx.xxx.1, which the virtual machine can use to communicate with the host.

If the gateway is not set correctly, it will directly cause the virtual machine to fail to communicate normally with the external network (especially in NAT mode). It is convenient for everyone to copy. The text is given below:

DEVICE=eth0TYPE=EthernetUUID=b56a4da9-b82a-4b32-9ee5-b2b08f546e64ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=static# sets IPADDR=192.168.19.145NETMASK=255.255.255.0GATEWAY=192.168.19.2# DNS1 according to the corresponding virtual machine network card or connected router network segment. The time point of the last connection of the main DNS server address DNS1=192.168.19.2DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME= "System eth0" USERCTL=noHWADDR=00:0C:29:98:FE:94PREFIX=24#: Unix timestamp LAST_CONNECT= 1576595442, network status control

When we need to make the latest configuration of the network card take effect, usually to restart the network card, we can use the following two common methods.

1. Service control

By directly restarting the network service, remember: this will affect all network cards! Therefore, it does not matter if it is a personal learning stage, if it is in a server environment with multiple network cards, please use it with caution.

Command format: service {service name} {service operation} service network status: view network service running status service network start: start network service service network stop: stop network service service network restart: restart network service

two。 Network card control

If we only want to restart a certain network card, we can use the ifconfig command, such as: ifconfig eth0 up/down. But the author prefers to use another simple command.

Disable eth0 network card: ifdown eth0 enable eth0 network card: ifup eth0 4, network master switch and DNS configuration 1. Network master switch related configuration file: / etc/sysconfig/network

For CentOS systems, there is also a network master switch profile. Of course, generally speaking, we only use this file when modifying the hostname of the system, in which there are two configuration items, one is the network master switch, the other is the hostname, as follows.

Only when the network master switch is turned on can the network service be used normally. But generally no one will change yes to no, it is good to know that most networks cannot work properly mainly because of the configuration file of the network card.

2. DNS configuration DNS configuration file: / etc/resolv.conf

As mentioned above, the DNS configuration in the Nic configuration file has a higher priority. After the Nic takes effect, the DNS configuration will be directly written to the DNS configuration file. So we can directly look at the contents of the resolv.conf to see what the DNS server address is currently used by the machine. If the DNS address is not specified in the configuration file of the network card, we can manually edit the file to add it. We just need to list the address in a new line.

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