Linux common commands - Network Command
1, ping command: to test network connectivity
ping command is a common network, the main network is detected by the ICMP protocol, detecting connectivity of the network hosts. Basic information is as follows:
- Name command: ping
- The path: / bin / ping
- Execute permissions: All users
- Description: to test network connectivity
- The basic format: ping [options] IP or domain name
Common options ping command:
- -b: broadcast address added later, detect for the entire segment;
- -c number: the number of times specified ping;
1.1> ping IP / Domain Name
In Linux, ping command will always be. You can use "Ctrl + C" shortcut key forcibly suspended.
[root@root 桌面]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=31.6 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=33.2 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=128 time=33.7 ms
64 bytes from 61.135.169.121: icmp_seq=4 ttl=128 time=32.4 ms
64 bytes from 61.135.169.121: icmp_seq=5 ttl=128 time=30.6 ms
......
1.2> ping -c number of IP / domain -> ping packet specified number of times
[root@root 桌面]# ping -c 3 www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_seq=1 ttl=128 time=32.7 ms
64 bytes from 61.135.169.121: icmp_seq=2 ttl=128 time=34.2 ms
64 bytes from 61.135.169.121: icmp_seq=3 ttl=128 time=31.2 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2054ms
rtt min/avg/max/mdev = 31.278/32.759/34.238/1.208 ms
1.3> "-b" option: broadcast address is added back (i.e., network ping), for testing of the entire network;
[root@root 桌面]# ping -b 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=2.95 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=2.57 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=128 time=2.06 ms
^C
--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2687ms
rtt min/avg/max/mdev = 2.067/2.533/2.956/0.368 ms
2, ifconfig command: View and set the card information
-
ifconfig (interfaces config), usually requires log in as root or use sudo to use ifconfig tool;
-
ifconfig command to view and configure network devices. When the network environment is changed corresponding to the configuration command through a secondary network;
-
NIC configuration information with the ifconfig command, restart the machine after the card or restart the machine, the configuration becomes ineffective. If you need to configure the long-term effective, we need to modify the configuration file;
ifconfig is Linux view and modify the IP address of the temporary order, basic information is as follows: -
Command name: ifconfig
-
The path: / sbin / ifconfig
-
Execute permissions: Super User
-
Description: View and set the card information
2.1> to view the IP address information
[root@root 桌面]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:9A:A0:31
inet addr:192.168.85.133 Bcast:192.168.85.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe9a:a031/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1629 errors:0 dropped:0 overruns:0 frame:0
TX packets:579 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:115321 (112.6 KiB) TX bytes:47994 (46.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5192 errors:0 dropped:0 overruns:0 frame:0
TX packets:5192 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:324462 (316.8 KiB) TX bytes:324462 (316.8 KiB)
Description:
(. 1) eth0 represents a card, wherein a physical address indicating HWaddr card, can see the current physical address of the NIC (MAC address) is 00: 16: 3E: 00: 1E: 51.
(2) inet addr indicates the IP address for the NIC, IP address of the network adapter is 10.160.7.81, a broadcast address
(3) Bcast: 10.160.15.255, Mask Address Mask: 255.255.240.0.
(4) lo is a bad return address of the host, which generally is used to test a web application, but do not want the user LAN or outside the network to view, and the view can only run on which network interfaces on this host. For example, the httpd
specified server to return a bad address, will be able to see what you stand WEB site in browser and enter 127.0.0.1. But
only you can see, the host or other LAN users do not know.
- First line: Connection Type: Ethernet (Ethernet) HWaddr (hardware mac address).
- Second row: NIC IP address, subnet mask.
- Third row: the UP (NIC on state on behalf of) the RUNNING (on behalf of the network cable is connected to the card) the MULTICAST (supports multicast) the MTU: 1500 (maximum transmission unit): 1500 bytes.
- Fourth, the five elements: receive and send data packets statistics.
- Seventh row: receive and send data bytes statistics.
2.2> temporary IP address configuration: Once the mid-host, will fail, if need long-term effective, you need to modify the configuration file;
[root@root 桌面]# ifconfig eth1 192.168.30.30
[root@root 桌面]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:5E:76:E7
inet addr:192.168.30.30 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5e:76e7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:153 errors:0 dropped:0 overruns:0 frame:0
TX packets:140 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12477 (12.1 KiB) TX bytes:11352 (11.0 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:38 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2724 (2.6 KiB) TX bytes:2724 (2.6 KiB)
2.3> Disable or re-activate the card
Format is as follows,
starts: ifconfig eth * up
prohibited: ifconfig eth * down
[root@root 桌面]# ifconfig eth1 down
[root@root 桌面]# ifconfig eth1 up
3, mail order: send and receive e-mail
mail is sent and received e-mail Linux commands, basic information is as follows:
- Command name: mail
- The path: / bin / mail
- Execute permissions: All users
- Description: send and receive email
mail recipient user name, for example: write messages to the root user, mail to view e-mail;
[root@redhat 桌面]# mail root
Subject: test
nihao hello
EOT
[root@redhat 桌面]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 8 messages 8 new
>N 1 Anacron Tue Mar 12 05:07 17/636 "Anacron job 'cron.dai"
N 2 Anacron Wed Mar 13 03:11 17/636 "Anacron job 'cron.dai"
N 3 Anacron Thu Mar 14 04:09 17/636 "Anacron job 'cron.dai"
N 4 Anacron Fri Mar 15 04:42 17/636 "Anacron job 'cron.dai"
N 5 Anacron Sat Mar 16 07:16 17/636 "Anacron job 'cron.dai"
N 6 Anacron Sat Mar 23 04:39 17/636 "Anacron job 'cron.dai"
N 7 Anacron Sun Mar 31 21:44 17/636 "Anacron job 'cron.dai"
N 8 root Tue Apr 2 20:00 18/588 "test"
& 8
Message 8:
From [email protected] Tue Apr 2 20:00:51 2019
Return-Path: <[email protected]>
X-Original-To: root
Delivered-To: [email protected]
Date: Tue, 02 Apr 2019 20:00:50 +0800
To: [email protected]
Subject: test
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
nihao hello
4, traceroute command: display the path between the packet to the host
traceroute command to display the packet data path between a host, the following basic information:
- Command name: traceroute
- The path: / bin / traceroute
- Execute permissions: All users
- Description: display the path between the packet to the host
traceroute: traceroute command, in * The figure is the target prohibit ping;
traceroute to www.sina.com.cn (112.25.53.229), 30 hops max, 60 byte packets
1 192.168.85.2 (192.168.85.2) 0.114 ms 0.081 ms 0.053 ms
2 * * *
3 * * *
4 * * *
5 * * *
5, netstat command: View network status
See netstat network status command, i.e., the machine can check the port open, can also see which clients are connected.
Basic information of netstat command is as follows:
- Command name: netstat
- The path: / bin / netstat
- Execute permissions: All users
- Description: Displays network information
netstat command common options:
- -t: lists TCP protocol port
- -u: UDP protocol port list
- -n: Do not use a domain name with the service name, and the IP address and port number
- -l: lists only state in listening network services (TCP there are only listening state)
- -a: lists all network connections
- -r: lists the routing list
- -p: PID and display program name
[root@root 桌面]# netstat -antl
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:39271 0.0.0.0:* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
tcp 0 0 :::33766 :::* LISTEN
Check your phone routing table:
[root@root 桌面]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.85.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
0.0.0.0 192.168.85.2 0.0.0.0 UG 0 0 0 eth1
6, setup command: configure the network
Basic information of the setup command as follows:
- Command name: setup
- The path: / usr / bin / setup
- Execute permissions: All users
- Description: Network Configuration
The following steps: setup the IP configuration, network management information (host restart is still valid);
7, nslookup command: domain name and IP address resolution
Basic information of nslookup command is as follows:
- Command name: nslookup
- The path: / usr / bin / nslookup
- Execute permissions: All users
- Description: domain name and IP address resolution
[root@root 桌面]# nslookup
> baidu.com
Server: 192.168.85.2
Address: 192.168.85.2#53
Non-authoritative answer:
Name: baidu.com
Address: 123.125.114.144
Name: baidu.com
Address: 220.181.38.148
> server
Default server: 192.168.85.2
Address: 192.168.85.2#53
8, route commands: View the routing table entries
Basic information route command is as follows:
- Command name: route
- The path: / sbin / route
- Execute permissions: root user
- Description: View or routing table settings host
[root@root 桌面]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.85.0 * 255.255.255.0 U 1 0 0 eth1
default 192.168.85.2 0.0.0.0 UG 0 0 0 eth1