Những câu lệnh thường dùng khi quản lý network trong Linux
1. Lệnh ping
Lệnh ping dùng để kiểm tra xem một server nào đấy có đang hoạt động hay không hoặc mình có thể kết nối với server đấy không. Lệnh Ping sẽ thử gửi IP packet đến địa chỉ IP của server cần kết nối, nếu có phản hồi từ server thì chứng tỏ server đang hoạt động và chúng ta có thể kết nối với server.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | [test@demo-docker ~]$ ping 10.146.0.3 PING 10.146.0.3 (10.146.0.3) 56(84) bytes of data. 64 bytes from 10.146.0.3: icmp_seq=1 ttl=64 time=0.054 ms 64 bytes from 10.146.0.3: icmp_seq=2 ttl=64 time=0.064 ms 64 bytes from 10.146.0.3: icmp_seq=3 ttl=64 time=0.063 ms 64 bytes from 10.146.0.3: icmp_seq=4 ttl=64 time=0.067 ms 64 bytes from 10.146.0.3: icmp_seq=5 ttl=64 time=0.063 ms ^C --- 10.146.0.3 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 3999ms rtt min/avg/max/mdev = 0.054/0.062/0.067/0.006 ms [test@demo-docker ~]$ | 
2. Lệnh nslookup
Lệnh nslookup dùng để xác định địa chỉ IP từ một tên miền.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | [test@demo-docker ~]$ nslookup tech.vtijapan.co.jp Server: 14.193.100.8 Address: 14.193.100.8#53 Non-authoritative answer: Name: tech.vtijapan.co.jp Address: 52.196.79.177 (👉địa chỉ IP của tech.vtijapan.co.jp) [test@demo-docker ~]$ [test@demo-docker ~]$ [test@demo-docker ~]$ nslookup www.yahoo.co.jp Server: 14.193.100.8 Address: 14.193.100.8#53 Non-authoritative answer: www.yahoo.co.jp canonical name = edge12.g.yimg.jp. (👉CNAME của www.yahoo.co.jp là edge12.g.yimg.jp) Name: edge12.g.yimg.jp Address: 182.22.25.252 (👉địa chỉ IP của edge12.g.yimg.jp và cũng là của www.yahoo.co.jp) [test@demo-docker ~]$ [test@demo-docker ~]$ [test@demo-docker ~]$ nslookup → server 8.8.8.8 (👉có thể chỉ định DNS server khi sử dụng nslookup) Default server: 8.8.8.8 Address: 8.8.8.8#53 → www.yahoo.co.jp Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: www.yahoo.co.jp canonical name = edge12.g.yimg.jp. Name: edge12.g.yimg.jp Address: 182.22.25.252 → exit [test@demo-docker ~]$ | 
3. Lệnh dig
Lệnh dig cũng dùng để xác định địa chỉ IP từ một tên miền nhưng trả về nhiều thông tin hơn lệnh nslookup.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | [test@demo-docker ~]$ dig www.yahoo.co.jp ; <<>> DiG 9.10.6 <<>> www.yahoo.co.jp ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10447 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;www.yahoo.co.jp. IN A ;; ANSWER SECTION: www.yahoo.co.jp. 371 IN CNAME edge12.g.yimg.jp. edge12.g.yimg.jp. 36 IN A 182.22.25.124 ;; AUTHORITY SECTION: g.yimg.jp. 638 IN NS gns12.yahoo.co.jp. g.yimg.jp. 638 IN NS gns02.yahoo.co.jp. ;; ADDITIONAL SECTION: gns02.yahoo.co.jp. 152 IN A 118.151.254.148 gns12.yahoo.co.jp. 168 IN A 124.83.255.100 ;; Query time: 194 msec ;; SERVER: 14.193.100.8#53(14.193.100.8) ;; WHEN: Sun Dec 02 23:28:00 JST 2018 ;; MSG SIZE rcvd: 160 [test@demo-docker ~]$ | 
4. Lệnh ifconfig
Lệnh ifconfig dùng để xem thông tin và thay đổi các thiết lập về network cho pc hoặc server.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | [test@demo-docker ~]$ ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP> inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=201<PERFORMNUD,DAD> gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 EHC26: flags=0<> mtu 0 XHC20: flags=0<> mtu 0 EHC29: flags=0<> mtu 0 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 70:56:81:c3:d9:45 inet6 fe80::417:19c9:16c4:fe6d%en0 prefixlen 64 secured scopeid 0x7 inet 192.168.0.12 netmask 0xffffff00 broadcast 192.168.0.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304 ether 02:56:81:c3:d9:45 media: autoselect status: inactive awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484 ether 5e:32:d1:98:4e:11 inet6 fe80::5c32:d1ff:fe98:4e11%awdl0 prefixlen 64 scopeid 0x9 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=60<TSO4,TSO6> ether 32:00:12:ea:be:c0 media: autoselect <full-duplex> status: inactive bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=63<RXCSUM,TXCSUM,TSO4,TSO6> ether 32:00:12:ea:be:c0 Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x2 member: en1 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 10 priority 0 path cost 0 nd6 options=201<PERFORMNUD,DAD> media: <unknown type> status: inactive utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000 inet6 fe80::2de9:e24e:baeb:e225%utun0 prefixlen 64 scopeid 0xc nd6 options=201<PERFORMNUD,DAD> [test@demo-docker ~]$ [test@demo-docker ~]$ | 
chỉ cho hiển thị thông tin của en0
| 1 2 3 4 5 6 7 8 9 10 11 | [test@demo-docker ~]$ ifconfig en0 en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 70:56:81:c3:d9:45 inet6 fe80::417:19c9:16c4:fe6d%en0 prefixlen 64 secured scopeid 0x7 inet 192.168.0.12 netmask 0xffffff00 broadcast 192.168.0.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active [test@demo-docker ~]$ [test@demo-docker ~]$ | 
hiển thị thông tin của tất cả các interface đang có
| 1 2 3 4 5 | [test@demo-docker ~]$ ifconfig -l lo0 gif0 stf0 EHC26 XHC20 EHC29 en0 p2p0 awdl0 en1 bridge0 utun0 [test@demo-docker ~]$ [test@demo-docker ~]$ | 
chỉ hiển thị thông tin của tất cả các interface đang chạy
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | [test@demo-docker ~]$ ifconfig -u lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP> inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=201<PERFORMNUD,DAD> en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 70:56:81:c3:d9:45 inet6 fe80::417:19c9:16c4:fe6d%en0 prefixlen 64 secured scopeid 0x7 inet 192.168.0.12 netmask 0xffffff00 broadcast 192.168.0.255 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304 ether 02:56:81:c3:d9:45 media: autoselect status: inactive awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484 ether 5e:32:d1:98:4e:11 inet6 fe80::5c32:d1ff:fe98:4e11%awdl0 prefixlen 64 scopeid 0x9 nd6 options=201<PERFORMNUD,DAD> media: autoselect status: active en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 options=60<TSO4,TSO6> ether 32:00:12:ea:be:c0 media: autoselect <full-duplex> status: inactive bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=63<RXCSUM,TXCSUM,TSO4,TSO6> ether 32:00:12:ea:be:c0 Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x2 member: en1 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 10 priority 0 path cost 0 nd6 options=201<PERFORMNUD,DAD> media: <unknown type> status: inactive utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000 inet6 fe80::2de9:e24e:baeb:e225%utun0 prefixlen 64 scopeid 0xc nd6 options=201<PERFORMNUD,DAD> [test@demo-docker ~]$ | 
chỉ hiển thị thông tin của tất cả các interface đang bị stop
| 1 2 3 4 5 6 7 8 | [test@demo-docker ~]$ ifconfig -d gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 EHC26: flags=0<> mtu 0 XHC20: flags=0<> mtu 0 EHC29: flags=0<> mtu 0 [test@demo-docker ~]$ | 
5. Lệnh netstat
Lệnh netstat (network statistics) dùng để xem thông tin về kết nối mạng, bảng định tuyến và các thông tin thống kê của các giao diện mạng khác nhau.
Ví dụ hiển thị thông tin bảng định tuyến bằng số (tức bằng ip chứ không cần sử dụng dns để chuyển qua tên miền)
| 1 2 3 4 5 6 7 8 9 10 | [test@demo-docker ~]$ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.146.0.1 0.0.0.0 UG 0 0 0 eth0 10.146.0.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 10.146.0.3 0.0.0.0 255.255.255.255 UH 0 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-4d4a08122995 [test@demo-docker ~]$ | 
hiển thị các giao diện mạng đang chạy
| 1 2 3 4 5 6 7 8 9 10 | [test@demo-docker ~]$ netstat -I Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg br-4d4a0 1500 0 0 0 0 0 0 0 0 BMRU docker0 1500 0 0 0 0 0 0 0 0 BMU eth0 1460 1106 0 0 0 795 0 0 0 BMRU lo 65536 0 0 0 0 0 0 0 0 LRU veth4ab3 1500 0 0 0 0 16 0 0 0 BMRU [test@demo-docker ~]$ | 
hiển thị tất các cổng tcp đang được sử dụng
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [test@demo-docker ~]$ netstat -ant Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 120 10.146.0.3:22 180.149.181.243:49682 ESTABLISHED tcp 0 0 10.146.0.3:43112 169.254.169.254:80 ESTABLISHED tcp 0 0 10.146.0.3:22 180.149.181.243:49930 ESTABLISHED tcp 0 0 10.146.0.3:43114 169.254.169.254:80 ESTABLISHED tcp 0 0 10.146.0.3:43110 169.254.169.254:80 CLOSE_WAIT tcp 0 0 10.146.0.3:43116 169.254.169.254:80 ESTABLISHED tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN [test@demo-docker ~]$ | 
hiển thị tất các cổng udp đang được sử dụng
| 1 2 3 4 5 6 7 8 | [test@demo-docker ~]$ netstat -anu Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 127.0.0.1:323 0.0.0.0:* udp 0 0 0.0.0.0:68 0.0.0.0:* udp6 0 0 ::1:323 :::* [test@demo-docker ~]$ | 
hiển thị thông tin tổng hợp của các protocol đang sử dụng
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | [test@demo-docker ~]$ netstat -s Ip: 555 total packets received 0 forwarded 0 incoming packets discarded 553 incoming packets delivered 365 requests sent out 2 dropped because of missing route Icmp: 0 ICMP messages received 0 input ICMP message failed. ICMP input histogram: 0 ICMP messages sent 0 ICMP messages failed ICMP output histogram: Tcp: 23 active connections openings 1 passive connection openings 1 failed connection attempts 0 connection resets received 4 connections established 528 segments received 342 segments send out 1 segments retransmited 0 bad segments received. 4 resets sent Udp: 25 packets received 0 packets to unknown port received. 0 packet receive errors 25 packets sent 0 receive buffer errors 0 send buffer errors UdpLite: TcpExt: 1 resets received for embryonic SYN_RECV sockets 9 delayed acks sent Quick ack mode was activated 2 times 36 packet headers predicted 238 acknowledgments not containing data payload received 12 predicted acknowledgments TCPLossProbes: 1 TCPLossProbeRecovery: 1 2 DSACKs sent for old packets 1 DSACKs received TCPRcvCoalesce: 47 TCPOrigDataSent: 229 IpExt: InNoRoutes: 2 InOctets: 89820 OutOctets: 47376 InNoECTPkts: 555 [test@demo-docker ~]$ | 
★ Nguồn tham khảo ★
https://news.mynavi.jp/article/20180719-665927/
https://qiita.com/miminashi/items/574f09b2f3fd5d9b89f3
https://qiita.com/toshihirock/items/1ff01a51570bf6ca4f59
http://www.atmarkit.co.jp/ait/series/2071/
http://www.atmarkit.co.jp/ait/articles/1412/10/news003.html



 
	        	        		 
	        	        		 
	        	        		 
	        	        		 
	        	        		 
	        	        		 
	        	        		