1. 程式人生 > 實用技巧 >Linux中的網路相關命令

Linux中的網路相關命令

1.網絡卡配置檔案
#網絡卡配置檔案
[root@lxy ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet #網路型別
BOOTPROTO=none #ip地址獲取方式 dhcp動態 靜態 static none
NAME=eth0 #網絡卡名
DEVICE=eth0 #裝置名
ONBOOT=yes #網絡卡是否開機自啟動
IPADDR=10.0.0.150 #IP地址
PREFIX=24 #子網掩碼 NETMASK=255.255.255.0
GATEWAY=10.0.0.2 #閘道器
DNS1=223.5.5.5 #主DNS
DNS2=223.6.6.6 #次DNS
2.ping網路的測試工具
ping        #網路的測試工具

-c #抓幾個包
-t #持續ping windows上面使用
-W #超時時間,秒級
-f #極速
3.nmap網路的掃描工具

nmap #網路的掃描工具
[root@lxy ~]# nmap -p22 10.0.0.150

Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-16 00:03 CST
Nmap scan report for 10.0.0.150
Host is up (0.00023s latency).
PORT STATE SERVICE
22/tcp open ssh
MAC Address: 00:0C:29:02:93:87 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
[root@lxy ~]# nmap -p1-80 10.0.0.150

Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-16 00:03 CST
Nmap scan report for 10.0.0.150
Host is up (0.00011s latency).
Not shown: 79 closed ports
PORT STATE SERVICE
22/tcp open ssh
MAC Address: 00:0C:29:02:93:87 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

[root@lxy ~]# nmap -p22,80 10.0.0.150

Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-16 00:04 CST
Nmap scan report for 10.0.0.150
Host is up (0.00018s latency).
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
MAC Address: 00:0C:29:02:93:87 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
[root@lxy ~]# nmap 10.0.0.150

Starting Nmap 6.40 ( http://nmap.org ) at 2020-01-16 00:04 CST
Nmap scan report for 10.0.0.150
Host is up (0.000089s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
MAC Address: 00:0C:29:02:93:87 (VMware)

Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
4.nc網路工具
nc      #網路工具,是netcat的簡寫,有著網路界的瑞士軍刀美譽。 
-u #指定nc使用UDP協議,預設為TCP udp協議
-l #監聽某個埠

#服務端
[root@lxy ~]# nc -l 80
a:123

#客戶端測試
[root@lxy ~]# nc 10.0.0.150 80
a:123
5.netstat 檢測系統網路資料
netstat     #檢測系統網路資料

-l #列出監聽的埠
-n #禁止主機和埠解析
-t #tcp協議
-u #udp協議
-p #顯示pid號及程序名稱
-a #列出所有的
-r #顯示路由表

-ant #顯示tcp的11種狀態

-rn #顯示路由表
6.ss 檢測系統網路資料
ss      #檢測系統網路資料

-l #列出監聽的埠
-n #禁止主機和埠解析
-t #tcp協議
-u #udp協議
-p #顯示pid號及程序名稱
-a #列出所有的

-ant #顯示tcp的11種狀態
7.telnet 遠端連線的服務,只支援普通使用者
telnet      #遠端連線的服務,只支援普通使用者 

#服務端操作
[root@lxy ~]# useradd test
[root@lxy ~]# echo '1' |passwd --stdin test
Changing password for user test.
passwd: all authentication tokens updated successfully.
[root@lxy ~]# yum install -y telnet-server
[root@lxy ~]# systemctl start telnet.socket
[root@lxy ~]# netstat -lntp | grep 23
tcp6 0 0 :::23 :::* LISTEN 1/systemd
[root@lxy ~]#

#客戶端測試
[C:\~]$ telnet 10.0.0.150

Connecting to 10.0.0.150:23...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
lxy login: root
Password:
Login incorrect

lxy login: test
Password:
阿米託福
[test@lxy ~]$

#測試主機是否開放某個埠
[C:\~]$ telnet 10.0.0.150 22

Connecting to 10.0.0.150:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
SSH-2.0-OpenSSH_7.4
8.iftop 檢查網絡卡資料的傳輸的流量,網絡卡的速率
iftop       #檢查網絡卡資料的傳輸的流量,網絡卡的速率 
-n #禁止解析主機名
-P #禁止解析埠
-i #監聽某一塊網絡卡
-B #以位元組的形式顯示

TX #流出流量
RX #流入的流量
TOTAL #總流量
cum #從執行iftop命令時的資料
perk #峰值

rates 分別表示過去2s 10s 40s的平均流量
按q退出監控
9.traceroute Linux路由跟蹤命令
路由跟蹤的命令 
[root@lxy ~]# yum install -y traceroute
traceroute #Linux路由跟蹤命令
-n #禁止解析域名
[root@lxy ~]# traceroute -n www.baidu.com

windows 路由跟蹤命令
C:\Users\oldboy>tracert -d www.baidu.com

通過最多 30 個躍點跟蹤
到 www.a.shifen.com [180.101.49.11] 的路由:

1 2 ms 1 ms 2 ms 192.168.11.1
2 4 ms 5 ms 3 ms 124.74.216.130 上海市上海市 電信
3 8 ms 4 ms 5 ms 124.74.216.129 上海市上海市 電信
4 6 ms 6 ms 8 ms 101.95.41.121 上海市上海市 電信
5 6 ms 6 ms 6 ms 61.152.25.30 上海市上海市 電信
6 11 ms 10 ms 12 ms 202.97.66.206 甘肅省 電信
7 11 ms 11 ms 11 ms 58.213.95.6 江蘇省南京市 電信
8 10 ms * * 58.213.95.86 江蘇省南京市 電信
9 10 ms 10 ms 11 ms 58.213.96.62 江蘇省南京市 電信
10 * * * 請求超時。
11 * * * 請求超時。
12 * * * 請求超時。
13 * * * 請求超時。
14 10 ms 10 ms 10 ms 180.101.49.11 江蘇省南京市 電信

跟蹤完成。

C:\Users\oldboy>tracert -d www.qq.com

通過最多 30 個躍點跟蹤
到 public-v6.sparta.mig.tencent-cloud.net [61.151.166.146] 的路由:

1 <1 毫秒 <1 毫秒 <1 毫秒 192.168.11.1
2 6 ms 4 ms 4 ms 124.74.216.130
3 6 ms 3 ms 7 ms 124.74.216.133
4 7 ms 11 ms 8 ms 124.74.210.5
5 * 5 ms * 101.95.219.202
6 * * 30 ms 101.89.246.22
7 12 ms * * 101.91.68.6
10.glances 實時顯示系統各種狀態
glances     #實時顯示系統各種狀態