How to perform network configuration and network troubleshooting on Linux systems

WBOY
Release: 2023-11-07 09:38:10
Original
1253 people have browsed it

How to perform network configuration and network troubleshooting on Linux systems

Linux system is a powerful server operating system. Network configuration and network troubleshooting are indispensable skills for operation and maintenance personnel. This article will introduce in detail how to perform network configuration and network troubleshooting on Linux systems, and provide specific code examples to help readers understand and master the relevant knowledge more deeply.

1. Network configuration

  1. Configure IP address

In the Linux system, the command to configure the IP address is to use ifconfig. We can use the following command To configure the IP address:

ifconfig eth0 192.168.1.100 netmask 255.255.255.0
Copy after login

Among them, eth0 represents the network card name, 192.168.1.100 represents the IP address, and 255.255.255.0 represents the subnet mask, which can be adjusted according to the actual situation.

  1. Configuring the gateway

The command to configure the gateway is route add. We can configure the gateway through the following command:

route add default gw 192.168.1.1
Copy after login

Among them, 192.168.1.1 represents The IP address of the gateway.

  1. Configure DNS

The command to configure DNS is to modify the resolv.conf file. We can modify it through the following command:

vi /etc/resolv.conf
Copy after login

In the open file , add the following content:

nameserver 8.8.8.8
nameserver 8.8.4.4
Copy after login

Among them, 8.8.8.8 and 8.8.4.4 represent Google’s public DNS server addresses, which can also be adjusted according to the actual situation.

2. Network troubleshooting

  1. Network connectivity test

Use the ping command to test whether the network is connected. Use the following command to test:

ping www.baidu.com
Copy after login

If the following results appear, it means the network is connected:

PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=50 time=29.3 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=50 time=29.3 ms
64 bytes from 61.135.169.125: icmp_seq=3 ttl=50 time=29.5 ms
Copy after login

If the following results appear, it means the network is not connected:

ping: unknown host www.google.com
Copy after login

At this time, you can check whether the DNS configuration is correct, or you can use Use the ip command to check the network connection status.

  1. View network connection status

Use the netstat command to check the network connection status. Check it with the following command:

netstat -an
Copy after login

Among them, -a means display For all connections, -n indicates to display the IP address and port number in numerical form.

If there are too many network connections, you can use the grep command to filter. For example:

netstat -an | grep 80
Copy after login

means that only connections with port number 80 will be displayed.

  1. Firewall configuration

If the network connection fails, you also need to check whether the firewall configuration is correct. Run the following command to check:

iptables -L
Copy after login

Among them, -L means list all rules. If you need to open a port, you can use the following command to configure it:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
Copy after login

Among them, --dport represents the port number that needs to be opened.

The above content is a detailed introduction to the Linux system network configuration and network troubleshooting in this article. I hope readers can master the relevant skills and apply them in actual operation and maintenance.

The above is the detailed content of How to perform network configuration and network troubleshooting on Linux systems. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!