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 to check the network status in CentOS

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about how to check the network status in CentOS. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

View network status:

Lsof-Pnl + M-i4 displays ipv4 services and listeners

Netstat-anp all listening ports and corresponding processes

Netstat-tlnp function is the same as above

Basic network command

(1) after the configuration information of the control network interface of network service is changed, the network service must be restarted to activate the new configuration of the network to make the configuration effective. This part of the operation is the same as booting the system from time to time. Control (control) is / etc/init.d/network this file, you can use this file followed by the following parameters to operate the network service. For example:

[root@linux ~] # / etc/init.d/networkrestart

You can also use the service command to operate network services such as:

[root@linux ~] # service network restart

Start ← startup

Stop ← stop

Restart ← restart

Reload ← is the same as restarting (..)

Status ← status representation

If the server software is installed in rpm, most of the above contents correspond to each other.

(2) network management commands there are also some commonly used commands in network management. Here are some commonly used commands.

Ifconfig

Netstat

Hostname

Ping

Traceroute

Ifconfig

This command can be used to start / stop the network interface, change the settings and represent the network state, and this ifconfig can represent the status of the network interface without adding any parameters. For example:

[root@linux ~] # ifconfig

Eth0 Link encap:Ethernet HWaddr00:xx:xx:xx:04:45

Inet addr:192.168.1.81 Bcast:192.168.1.255 Mask:255.255.255.0

Inet6 addr: fe80::20c:29ff:fe61:445/64 Scope:Link

UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RXpackets:472 errors:0 dropped:0 overruns:0 frame:0

TXpackets:445 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:1000

RXbytes:35804 (34.9 KiB) TX bytes:53012 (51.7 KiB)

Interrupt:185 Base address:0x1080

Lo Link encap:Local Loopback

Inet addr:127.0.0.1 Mask:255.0.0.0

Inet6 addr: 1/128 Scope:Host

UPLOOPBACK RUNNING MTU:16436 Metric:1

RXpackets:8 errors:0 dropped:0 overruns:0 frame:0

TXpackets:8 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:0

RXbytes:560 (560.0b) TX bytes:560 (560.0b)

[root@linux ~] #

Look at the output of ifconfig.

1. Link encap ←

2. HWaddr ← MAC address

3.inet addr ← IP address (IPV4)

4. Bcast ← broadcast address

5. Mask ← derivative code

6. Inet6 addr ← IP address (IPV6)

7. UP ← is starting

8. BROADCAST ← broadcast address is valid

9. RUNNING ← action

10. MTU of MTU ← network interface (MaximumTransfer Unit:Ethernet maximum transport frame value)

11. Metric ←

12. Number of RX packets ← trusted packets

13. Number of packets delivered by TX packets ←

14. Collisions ←

15. Interrupt ← IRQ number

16. Baseaddress ← iUnio address

Through this command, you can also up and down a certain network interface (network card). For example, if we turn off eth0, we can use the following command:

[root@linux ~] # ifconfigeth0 down

The opposite turns on as follows:

[root@linux ~] # ifconfigeth0 up

You can also set the network interface (network card) through this command. For example, we set the IP of eth0 to 192.168.1.11 and the subnet derivative to 255.255.255.0 as follows:

[root@linux ~] # ifconfigetho inet 192.168.1.11 netmask 255.255.255.0

If there is more than one network interface, the X part of the ethX uses the network interface code (numbers, such as eth0,eth2,eth3).

Netstat

This command is a command that shows the various conditions of the network and will represent the intelligence of Active Internet connections and ActiveUNIX domain sockets without following any parameters being executed.

Take a look at the following output:

Here is how 192.168.1.56 is connecting to 192.168.1.81 through ssh

[root@linux ~] # netstat

Active Internetconnections (w _ servers)

Proto Recv-Q Send-QLocal Address ForeignAddress State

Tcp 0 0:: ffff:192.168.1.81:ssh:: ffff:192.168.1.56:4757 ESTABLISHED

Active UNIX domainsockets (w _ servers)

Proto RefCntFlags Type State I-Node Path

Unix 11 [] DGRAM 5202 / dev/log

Unix 2 [] DGRAM 5997 @ / var/run/hal/hotplug_socket

Unix 2 [] DGRAM 2536 @ udevd

Unix 2 [] DGRAM 7474

Unix 3 [] STREAM CONNECTED 5995 / var/run/dbus/system_bus_socket

Unix 3 [] STREAM CONNECTED 5994

Unix 3 [] STREAM CONNECTED 5974

Unix 3 [] STREAM CONNECTED 5973

Unix 2 [] DGRAM 5933

Unix 2 [] DGRAM 5923

Unix 2 [] DGRAM 5876

Unix 2 [] DGRAM 5819

Unix 2 [] DGRAM 5805

Unix 2 [] DGRAM 5786

Unix 2 [] DGRAM 5723

Unix 3 [] STREAM CONNECTED 5388

Unix 3 [] STREAM CONNECTED 5387

Unix 2 [] DGRAM 5280

Unix 2 [] DGRAM 5210

[root@linux ~] #

The main options:

-a displays all socket, including those that are being monitored.

-c is redisplayed every 1 second until the user interrupts it.

-I displays information about all network interfaces in the same format as "ipconfig-e".

-n replaces the name with the network IP address, showing the network connection.

-r displays the core routing table in the same format as "route-e".

-t displays the connection of the TCP protocol.

-u shows the connection of the UDP protocol.

-v shows the work in progress.

The above options can be used in combination. For example, if we want to know the TCP port that is being opened, we can use the following situation to perform the inspection:

[root@linux ~] # netstat-at

Active Internetconnections (servers and established)

Proto Recv-Q Send-QLocal Address ForeignAddress State

Tcp 0 0 *: 617 *: * LISTEN

Tcp 0 0 *: sunrpc *: * LISTEN

Tcp 0 0 *: ipp *: * LISTEN

Tcp 0 0 linux.xiaoqi.ddo.jp:smtp *: * LISTEN

Tcp 0 0 *: ssh *: * LISTEN

Tcp 0 132:: ffff:192.168.1.81:ssh:: ffff:192.168.1.56:4757 ESTABLISHED

[root@linux ~] #

You can try other ways to use it yourself. ..

Hostname

This command is used to denote hostname and set hostname, and will represent the current hostname without following any options, such as the following output:

[root@linux ~] # hostname

Linux.xiaoqi.ddo.jp

[root@linux ~] #

In the case of root login, you can change the hostname. For example, if we rename the current hostname to centos, it is as follows:

[root@linux ~] # hostname centos

[root@linux ~] # hostname

Centos

[root@linux ~] #

Ping

This command determines whether the target host is working or connected to the network by sending ICMP packets to the destination address. The parameter is the IP address of the destination CVM. For example, if we want to know whether the network configuration of our CVM is normal, we can judge it by ping our own CVM, as shown below:

[root@linux ~] # pinglocalhost / / the localhost in this place can be replaced by 127.0.0.1, or the destination address IP address or domain name. This command is usually used to access the DNS server to obtain the IP address or domain name of the target host.

PING linux.xiaoqi.ddo.jp (127.0.0.1) 56 (84) bytes ofdata.

64 bytes fromlinux.xiaoqi.ddo.jp (127.0.0.1): icmp_seq=0 ttl=64 time=0.999 ms

64 bytes fromlinux.xiaoqi.ddo.jp (127.0.0.1): icmp_seq=1 ttl=64 time=0.630 ms

-linux.xiaoqi.ddo.jp ping statistics

2 packetstransmitted, 2 received, 0 packet loss, time 1001ms / / Note that a 0% in this place indicates that the network is normal, when X% X is a number other than 0 indicates that there is a problem with the network, or when the ping command is executed, words such as time out will be displayed.

Rtt min/avg/max/mdev= 0.630/0.814/0.999/0.186 ms, pipe 2

[root@linux ~] #

The main options for the Ping command are as follows:

The number of-c stops after the specified number of packets are sent.

-d sets the options for SO_DEBUG.

-f send network packets to a machine massively and quickly to see its response.

-set the number of seconds to send a network packet to a machine at intervals of several seconds. The default value is once a second.

-l send packet data to the specified machine in the fastest way within a specified number of times (only superusers can use this option).

-Q does not display any information about the delivery packet, only the final result.

-r packets are sent directly to a machine without going through the gateway, usually to see if there is something wrong with the local network interface.

The number of-s bytes specifies the number of bytes of data to be sent. The default value is 56. Plus 8 bytes of ICMP headers, the total is 64ICMP data bytes.

More information and more commands can be learned little by little in the process of use, and when you encounter problems, you can use the

# man command

To view the usage of the command

3. Basic network commands

(1) after the configuration information of the control network interface of network service is changed, the network service must be restarted to activate the new configuration of the network to make the configuration effective. This part of the operation is the same as booting the system from time to time. Control (control) is / etc/init.d/network this file, you can use this file followed by the following parameters to operate the network service. For example:

[root@linux ~] # / etc/init.d/networkrestart

You can also use the service command to operate network services such as:

[root@linux ~] # service network restart

Start ← startup

Stop ← stop

Restart ← restart

Reload ← is the same as restarting (..)

Status ← status representation

If the server software is installed in rpm, most of the above contents correspond to each other.

(2) network management commands there are also some commonly used commands in network management. Here are some commonly used commands.

Ifconfig

Netstat

Hostname

Ping

Traceroute

Ifconfig

This command can be used to start / stop the network interface, change the settings and represent the network state, and this ifconfig can represent the status of the network interface without adding any parameters. For example:

[root@linux ~] # ifconfig

Eth0 Link encap:Ethernet HWaddr00:xx:xx:xx:04:45

Inet addr:192.168.1.81 Bcast:192.168.1.255 Mask:255.255.255.0

Inet6 addr: fe80::20c:29ff:fe61:445/64 Scope:Link

UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RXpackets:472 errors:0 dropped:0 overruns:0 frame:0

TXpackets:445 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:1000

RXbytes:35804 (34.9 KiB) TX bytes:53012 (51.7 KiB)

Interrupt:185 Base address:0x1080

Lo Link encap:Local Loopback

Inet addr:127.0.0.1 Mask:255.0.0.0

Inet6 addr: 1/128 Scope:Host

UPLOOPBACK RUNNING MTU:16436 Metric:1

RXpackets:8 errors:0 dropped:0 overruns:0 frame:0

TXpackets:8 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:0

RXbytes:560 (560.0b) TX bytes:560 (560.0b)

[root@linux ~] #

Look at the output of ifconfig.

1. Link encap ←

2. HWaddr ← MAC address

3.inet addr ← IP address (IPV4)

4. Bcast ← broadcast address

5. Mask ← derivative code

6. Inet6 addr ← IP address (IPV6)

7. UP ← is starting

8. BROADCAST ← broadcast address is valid

9. RUNNING ← action

10. MTU of MTU ← network interface (MaximumTransfer Unit:Ethernet maximum transport frame value)

11. Metric ←

12. Number of RX packets ← trusted packets

13. Number of packets delivered by TX packets ←

14. Collisions ←

15. Interrupt ← IRQ number

16. Baseaddress ← iUnio address

Through this command, you can also up and down a certain network interface (network card). For example, if we turn off eth0, we can use the following command:

[root@linux ~] # ifconfigeth0 down

The opposite turns on as follows:

[root@linux ~] # ifconfigeth0 up

You can also set the network interface (network card) through this command. For example, we set the IP of eth0 to 192.168.1.11 and the subnet derivative to 255.255.255.0 as follows:

[root@linux ~] # ifconfigetho inet 192.168.1.11 netmask 255.255.255.0

If there is more than one network interface, the X part of the ethX uses the network interface code (numbers, such as eth0,eth2,eth3).

Netstat

This command is a command that shows the various conditions of the network and will represent the intelligence of Active Internet connections and ActiveUNIX domain sockets without following any parameters being executed.

Take a look at the following output:

Here is how 192.168.1.56 is connecting to 192.168.1.81 through ssh

[root@linux ~] # netstat

Active Internetconnections (w _ servers)

Proto Recv-Q Send-QLocal Address ForeignAddress State

Tcp 0 0:: ffff:192.168.1.81:ssh:: ffff:192.168.1.56:4757 ESTABLISHED

Active UNIX domainsockets (w _ servers)

Proto RefCntFlags Type State I-Node Path

Unix 11 [] DGRAM 5202 / dev/log

Unix 2 [] DGRAM 5997 @ / var/run/hal/hotplug_socket

Unix 2 [] DGRAM 2536 @ udevd

Unix 2 [] DGRAM 7474

Unix 3 [] STREAM CONNECTED 5995 / var/run/dbus/system_bus_socket

Unix 3 [] STREAM CONNECTED 5994

Unix 3 [] STREAM CONNECTED 5974

Unix 3 [] STREAM CONNECTED 5973

Unix 2 [] DGRAM 5933

Unix 2 [] DGRAM 5923

Unix 2 [] DGRAM 5876

Unix 2 [] DGRAM 5819

Unix 2 [] DGRAM 5805

Unix 2 [] DGRAM 5786

Unix 2 [] DGRAM 5723

Unix 3 [] STREAM CONNECTED 5388

Unix 3 [] STREAM CONNECTED 5387

Unix 2 [] DGRAM 5280

Unix 2 [] DGRAM 5210

[root@linux ~] #

The main options:

-a displays all socket, including those that are being monitored.

-c is redisplayed every 1 second until the user interrupts it.

-I displays information about all network interfaces in the same format as "ipconfig-e".

-n replaces the name with the network IP address, showing the network connection.

-r displays the core routing table in the same format as "route-e".

-t displays the connection of the TCP protocol.

-u shows the connection of the UDP protocol.

-v shows the work in progress.

The above options can be used in combination. For example, if we want to know the TCP port that is being opened, we can use the following situation to perform the inspection:

[root@linux ~] # netstat-at

Active Internetconnections (servers and established)

Proto Recv-Q Send-QLocal Address ForeignAddress State

Tcp 0 0 *: 617 *: * LISTEN

Tcp 0 0 *: sunrpc *: * LISTEN

Tcp 0 0 *: ipp *: * LISTEN

Tcp 0 0 linux.xiaoqi.ddo.jp:smtp *: * LISTEN

Tcp 0 0 *: ssh *: * LISTEN

Tcp 0 132:: ffff:192.168.1.81:ssh:: ffff:192.168.1.56:4757 ESTABLISHED

[root@linux ~] #

You can try other ways to use it yourself. ..

Hostname

This command is used to denote hostname and set hostname, and will represent the current hostname without following any options, such as the following output:

[root@linux ~] # hostname

Linux.xiaoqi.ddo.jp

[root@linux ~] #

In the case of root login, you can change the hostname. For example, if we rename the current hostname to centos, it is as follows:

[root@linux ~] # hostname centos

[root@linux ~] # hostname

Centos

[root@linux ~] #

Ping

This command determines whether the target host is working or connected to the network by sending ICMP packets to the destination address. The parameter is the IP address of the destination CVM. For example, if we want to know whether the network configuration of our CVM is normal, we can judge it by ping our own CVM, as shown below:

[root@linux ~] # pinglocalhost / / the localhost in this place can be replaced by 127.0.0.1, or the destination address IP address or domain name. This command is usually used to access the DNS server to obtain the IP address or domain name of the target host.

PING linux.xiaoqi.ddo.jp (127.0.0.1) 56 (84) bytes ofdata.

64 bytes fromlinux.xiaoqi.ddo.jp (127.0.0.1): icmp_seq=0 ttl=64 time=0.999 ms

64 bytes fromlinux.xiaoqi.ddo.jp (127.0.0.1): icmp_seq=1 ttl=64 time=0.630 ms

-linux.xiaoqi.ddo.jp ping statistics

2 packetstransmitted, 2 received, 0 packet loss, time 1001ms / / Note that a 0% in this place indicates that the network is normal, when X% X is a number other than 0 indicates that there is a problem with the network, or when the ping command is executed, words such as time out will be displayed.

Rtt min/avg/max/mdev= 0.630/0.814/0.999/0.186 ms, pipe 2

[root@linux ~] #

The main options for the Ping command are as follows:

The number of-c stops after the specified number of packets are sent.

-d sets the options for SO_DEBUG.

-f send network packets to a machine massively and quickly to see its response.

-set the number of seconds to send a network packet to a machine at intervals of several seconds. The default value is once a second.

-l send packet data to the specified machine in the fastest way within a specified number of times (only superusers can use this option).

-Q does not display any information about the delivery packet, only the final result.

-r packets are sent directly to a machine without going through the gateway, usually to see if there is something wrong with the local network interface.

The number of-s bytes specifies the number of bytes of data to be sent. The default value is 56. Plus 8 bytes of ICMP headers, the total is 64ICMP data bytes.

After reading the above, do you have any further understanding of how to check the network status in CentOS? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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