Home  >  Article  >  System Tutorial  >  How can a network expert not understand these Linux ‘network configuration’ and ‘troubleshooting’ commands?

How can a network expert not understand these Linux ‘network configuration’ and ‘troubleshooting’ commands?

王林
王林forward
2024-03-18 16:22:02554browse

1. ifconfig

In the Linux kernel, the ifconfig command plays an important role in configuring and displaying network interface parameters. Through the ifconfig command, users can perform various configurations on the network interface. However, it should be noted that the network card information configured using the ifconfig command will become invalid once the network card is restarted or the machine is restarted. If you want to save these configuration information permanently in the computer, you need to modify the configuration file of the corresponding network card. In this way, the configuration will be retained even if the system is restarted.

网工高手,哪有不懂这些 Linux ‘网络配置’ 和 ‘故障排除’ 命令的?

# ifconfig

eth0: flags=4163 mtu 1500
inet 172.24.186.123 netmask 255.255.240.0 broadcast 172.24.191.255
ether 00:16:3e:24:5d:8c txqueuelen 1000 (Ethernet)
RX packets 36773275 bytes 9755326821 (9.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31552596 bytes 6792314542 (6.3 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 36893510 bytes 27158894604 (25.2 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36893510 bytes 27158894604 (25.2 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig With network port (eth0) command only displays specific interface details, such as IP Address, MAC Address, etc. With -a option will show all available interface details if it is also disabled.

# ifconfig eth0

Assign IP address and gateway

Assign an IP Address and Gateway instant interface. If the system is restarted, this setting will be deleted.

# ifconfig eth0 192.168.1.110 netmask 255.255.255.0

Enable or disable specific network ports

enable or disable, we use the example command as follows.

unsetunset启用 eth0unsetunset
# ifup eth0
unsetunsetDisable eth0unsetunset
# ifdown eth0

Set MTU size

By default the MTU size is 1500. We can set the desired MTU size with the following command. Replace XXXX with size.

# ifconfig eth0 mtu XXXX

Set the interface to promiscuous mode

Network interface Only received packets belong to that specific NIC. If you put the interface in promiscuous mode it will receive all packets. This is useful for capturing packets and analyzing them later. To do this, you may need superuser access.

# ifconfig eth0 - promisc

2. ping command

The ping command is used to test the network connectivity between hosts. Executing the ping command will use the ICMP transport protocol to send a message requesting a response. If there is no problem with the network function of the remote host, it will respond to the message, thus knowing that the host is operating normally.

# ping 127.0.0.1
or
# ping www.rumenz.com

In Linux the ping command is executed until you interrupt it. Ping with -c option after exiting N number of requests (success or error response).

# ping -c 5 www.rumenz.com
PING www.rumenz.com (42.194.162.109) 56(84) bytes of data.
64 bytes from 42.194.162.109 (42.194.162.109): icmp_seq=1 ttl=52 time=35.8 ms
64 bytes from 42.194.162.109 (42.194.162.109): icmp_seq=2 ttl=52 time=35.6 ms
64 bytes from 42.194.162.109 (42.194.162.109): icmp_seq=3 ttl=52 time=35.6 ms
64 bytes from 42.194.162.109 (42.194.162.109): icmp_seq=4 ttl=52 time=35.6 ms
64 bytes from 42.194.162.109 (42.194.162.109): icmp_seq=5 ttl=52 time=35.6 ms

--- www.rumenz.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 35.662/35.720/35.893/0.190 ms

3. traceroute command

traceroute is a network troubleshooting utility that displays the number of hops taken to reach a destination, which also determines the path a packet takes. Below we are tracing the route to the global DNS server IP Address and being able to reach the destination also shows the path that the packet is traveling.

# traceroute 8.8.8.8

4. netstat command

The netstat command is used to print the status information of the network system in Linux, allowing you to know the network status of the entire Linux system.

# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
link-local 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.24.176.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0

5. dig command

dig command is a commonly used domain name query tool, which can be used to test whether the domain name system is working properly.

# dig www.rumenz.com

; > DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.7 > www.rumenz.com
;; global options: cmd
;; Got answer:
;; ->>HEADER#53(100.100.2.136)
;; WHEN: Sat Nov 20 21:45:32 CST 2021
;; MSG SIZE rcvd: 48

6. nslookup command

The

nslookup command is also used to find DNS related queries. The following example shows A Record (IP Address) of rumenz.com.

# nslookup www.rumenz.com
Server: 100.100.2.136
Address: 100.100.2.136#53

Non-authoritative answer:
Name: www.rumenz.com
Address: 42.194.162.109

7. route command

route` command also displays and manipulates the `ip` routing table. View the default routing table`Linux
#route

Use the following commands to add, delete routes and default gateways.

unsetunsetAdd routeunsetunset
# route add -net 10.10.10.0/24 gw 192.168.0.1
unsetunsetDelete routeunsetunset
# route del -net 10.10.10.0/24 gw 192.168.0.1
unsetunsetAdd default gatewayunsetunset
# route add default gw 192.168.0.1

8. host command

host Command to find name IP or IP Name IPv4 or IPv6 and query DNS records.

# host www.rumenz.com
www.rumenz.com has address 42.194.162.109

Using the -t option we can find out the DNS resource records, such as CNAME, NS, MX, SOA etc.

//Install first
# yum install bind-utils -y
# host -t CNAME www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.

9. arp command

The arp command is the Address Resolution Protocol. It is an extremely important network transmission protocol in a network protocol package that finds the data link layer address by parsing the network layer address. This command can display and modify the buffered data in the arp protocol parsing table.

# arp -e
Address HWtype HWaddress Flags Mask Iface
gateway ether ee:ff:ff:ff:ff:ff C eth0

10. ethtool command

The ethtool command is used to obtain the configuration information of the Ethernet card, or to modify these configurations. This command is relatively complex and has many functions.

# ethtool eth0
Settings for eth0:
Link detected: yes

11. iwconfig command

iwconfig The system configures wireless network devices or displays wireless network device information. The iwconfig command is similar to the ifconfig command, but its configuration object is a wireless network card, which performs wireless operations on network devices, such as setting wireless communication bands

//Install first
# yum install -y wireless-tools
# iwconfig [interface]
eth0 no wireless extensions.

12. hostname command

hostname is identified in the network. Execute the hostname command to view the hostname of the machine. The hostname can be set permanently in /etc/sysconfig/network. A reboot is required after setting the correct hostname.

# hostname
rumenz.com

The above is the detailed content of How can a network expert not understand these Linux ‘network configuration’ and ‘troubleshooting’ commands?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete