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 does the Linux system check the network connection

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the Linux system how to check the network connection, the article is very detailed, has a certain reference value, interested friends must read it!

Ifquery command

A very useful command is ifquery. This command should display a list of network interfaces. However, you may only see something like this-only the loopback interface is displayed:

$ifquery-listlo

If this is the case, your / etc/network/interfaces does not include network interface information other than the loopback interface. In the following example, suppose you use DHCP to assign addresses, and if you want it to be more useful, you can add the last two lines of the example.

# interfaces (5) file used by ifup (8) and ifdown (8) auto loiface lo inet loopbackauto eth0iface eth0 inet dhcpifup and ifdown commands

You can use the relevant ifup and ifdown commands to open the network connection and close it as needed, as long as the file has the required descriptive data. Remember, "if" here means interface interface, which is the same as in the ifconfig command, not if I have only one "if" in the brain if I only had a brain.

Ifconfig command

In addition, the ifconfig command does not read / etc/network/interfaces at all, but still provides a lot of useful information about network interfaces-configuration data and packet counts that tell you how busy each interface is. The ifconfig command can also be used to shut down and restart network interfaces (for example, ifconfig eth0 down).

$ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:1e:4f:c8:43:fcinet addr:192.168.0.6 Bcast:192.168.0.255 Mask:255.255.255.0inet6 addr: fe80::b44b:bdb6:2527:6ae9/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:60474 errors:0 dropped:0 overruns:0 frame:0TX packets:33463 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:43922053 (43.9 MB) TX bytes:4000460 (4.0 MB) Interrupt:21 Memory:fe9e0000-fea00000

The RX and TX packet counts in the output are very low. In addition, no errors or packet conflicts are reported. It may be possible to use the uptime command to confirm that the system has only recently restarted.

The broadcast (Bcast) and Network Mask (Mask) addresses shown above indicate that the system is running on a Class C equivalent network (the default), so the local address range is from 192.168.0.1 to 192.168.0.254.

Netstat command

The netstat command provides information about routing and network connections. The netstat-rn command displays the routing table of the system. 192.168.0.1 is the local gateway (Flags=UG).

$netstat-rnKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface0.0.0.0 192.168.0.1 0.0.0.0 UG 0 000 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 000 eth0192.168.0.0 0.0.0.0 255.255.255.0 U 000 eth0

The 169.254.0.0 entry in the above output is only necessary if you are using or planning to use link-local communications. If this is not the case, you can comment out the relevant lines in / etc/network/if-up.d/avahi-autoipd:

$tail-12 / etc/network/if-up.d/avahi-autoipd#if [- x / bin/ip]; then# # route already present?# ip route show | grep-Q'^ 169.254.0.0 scope link#elif 16 [[: space:]]'& & exit 0pound # / bin/ip route add 169.254.0.0 dev $IFACE metric 1000 scope link#elif [- x / sbin/route] Then# # route already present?# / sbin/route-n | egrep-Q "^ 169.254.0.0 [[: space:]]" & & exit 04th # / sbin/route add-net 169.254.0.0 netmask 255.255.0.0 dev $IFACE metric 1000#finetstat-a command

The netstat-a command displays "all" network connections. To limit it to showing listening and established connections (usually more useful), use the netstat-at command instead.

$netstat-atActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address Statetcp 0 0 *: ssh *: * LISTENtcp 0 0 localhost:ipp *: * LISTENtcp 0 0 localhost:smtp *: * LISTENtcp 0 256 192.168.0.6:ssh 192.168.0.32 192.168.0.6:ssh 53550 ESTABLISHEDtcp6 0 0 [:]: http [::]: * LISTENtcp6 0 0 [::]: ssh [::]: * LISTENtcp6 00 ip6-localhost:ipp [::]: * LISTENtcp6 00 ip6-localhost:smtp [::]: * LISTENhost command

The host command, like nslookup, is used to query the IP address of the remote system, but also provides the mailbox processing address of the system.

$host world.std.comworld.std.com has address 192.74.137.5world.std.com mail is handled by 10 smtp.theworld.com.nslookup command

Nslookup also provides information about the DNS query service provided in the system (in this case, the local system).

$nslookup world.std.comServer: 127.0.1.1Address: 127.0.1.1#53Non-authoritative answer:Name: world.std.comAddress: 192.74.137.5dig command

The dig command provides a lot of information about connecting to a remote system-including the name server that communicates with us and how long it takes for queries to respond, and is often used for troubleshooting.

$dig world.std.com; > DiG 9.10.3-P4-Ubuntu > world.std.com;; global options: + cmd;; Got answer:;;-> > HEADER#53 (127.0.1.1); WHEN: Mon Oct 09 13:26:46 EDT 2017; MSG SIZE rcvd: 58nmap command

Nmap is often used to probe remote systems, but it is also used to report services provided by local systems. In the output below, we can see that the login can use ssh, smtp for email, the web site is enabled, and the ipp printing service is running.

Nmap localhostStarting Nmap 7.01 (https://nmap.org) at 2017-10-09 15:01 EDTNmap scan report for localhost (127.0.0.1) Host is up (0.00016s latency). Not shown: 996 closed portsPORT STATE SERVICE22/tcp open ssh25/tcp open smtp80/tcp open http631/tcp open ippNmap done: 1 IP address (1 host up) scanned in 0.09 seconds is all the content of this article "how do Linux systems check network connectivity". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report