一.Linux網(wǎng)絡(luò)管理命令
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、成都做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、太和ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的太和網(wǎng)站制作公司
1.Ifconfig命令
ifconfig顯示當(dāng)前網(wǎng)絡(luò)信息
格式: ifconfig [INTERFACE]
常用選項(xiàng):
-a:查看所有信息
ifconfig IFACE up|down 啟用|禁用某網(wǎng)卡接口
ifconfig interface [aftype] options | address ...
# ifconfig IFACE IP/mask [up]
# ifconfig IFACE IP netmask MASK
啟用混雜模式:[-]promisc
Note:啟用后立即生效。再次開機(jī)后不會(huì)再生效!
Eg:禁用eth2接口
[root@localhost ~]# ifconfig eth2 down [root@localhost ~]# ifconfig //可以看到eth2已經(jīng)不再顯示了 eth0 Link encap:Ethernet HWaddr 00:0C:29:7B:65:71 inet addr:172.16.249.202 Bcast:172.16.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fe7b:6571/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:159414 errors:0 dropped:0 overruns:0 frame:0 TX packets:4673 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12952278 (12.3 MiB) TX bytes:666573 (650.9 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:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
2.Route命令
常用選項(xiàng):
-n: 查看路由表信息
格式: route add|del [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
add | del
-net: 添加|刪除一個(gè)網(wǎng)絡(luò)路由(即添加網(wǎng)段)
-host: 添加|刪除一個(gè)主機(jī)路由
-gw : 添加| 刪除網(wǎng)關(guān)
-netmask:添加|刪除子網(wǎng)掩碼
default:添加|刪除 默認(rèn)路由
Eg1:給eth0添加一個(gè)主機(jī)路由為192.168.1.3,默認(rèn)網(wǎng)關(guān)為172.16.0.1
[root@localhost ~]# route add -host 192.168.1.3 gw 172.16.0.1 dev eth0 [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.3 172.16.0.1 255.255.255.255 UGH 0 0 0 eth0 192.168.27.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth2 172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0 刪除192.168.1.3這個(gè)路由 [root@localhost ~]# route del -host 192.168.1.3 [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.27.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth2 172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0 [root@localhost ~]# 刪除此路由條目 [root@localhost ~]# route del -net 192.168.0.0/24 [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.27.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth2 172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0 或者[root@localhost ~]# route del -net 192.168.0.0 netmask 255.255.255.0 Eg2:給eth0接口添加一個(gè)網(wǎng)絡(luò)路由為192.168.0.0默認(rèn)網(wǎng)關(guān)為 172.16.0.1 [root@localhost ~]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0 [root@localhost ~]# route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0
3.Netstat命令
1>.顯示網(wǎng)絡(luò)連接:
格式: netstat [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--numeric-hosts][--numeric-ports][--numeric-ports] [--symbolic|-N] [--extend|-e[--extend|-e]]
常用選項(xiàng):
-t :tcp協(xié)議相關(guān)
-u :udp協(xié)議相關(guān)
-l :監(jiān)聽的套接字 //常跟-t,-u選項(xiàng)
-p :打印信息
-e :擴(kuò)展信息
-n :以數(shù)字形式顯示
-p: 顯示相關(guān)pid信息
Eg:以數(shù)字形式顯示當(dāng)前主機(jī)下tcp協(xié)議都監(jiān)聽那些端口并打印出來 [root@chang ~]# netstat -tnlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1821/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1612/cupsd tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2181/sshd tcp 0 0 0.0.0.0:50982 0.0.0.0:* LISTEN 1580/rpc.statd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1478/rpcbind tcp 0 0 :::22 :::* LISTEN 1821/sshd tcp 0 0 ::1:631 :::* LISTEN 1612/cupsd tcp 0 0 ::1:25 :::* LISTEN 1935/master tcp 0 0 :::35321 :::* LISTEN 1580/rpc.statd tcp 0 0 ::1:6010 :::* LISTEN 2181/sshd tcp 0 0 :::111 :::* LISTEN 1478/rpcbind
2>.顯示路由信息
格式:netstat {--route|-r} [--numeric|-n][--numeric-hosts][--numeric-ports][--numeric-ports]
常用選項(xiàng):
-r: 顯示內(nèi)核路由表
-n: 以數(shù)字格式顯示
3>.顯示接口統(tǒng)計(jì)數(shù)據(jù)
netstat {--interfaces|-I|-i} [iface] [-all|-a] [--extend|-e] [--program|-p]
常用選項(xiàng):
-i : 顯示所有的接口信息
-I IFACE : 顯示多指定的接口信息
二.Linux網(wǎng)絡(luò)屬性命令
1.Ip 命令
格式: ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT := { link | addr | route }
ip link - network device configuration
set DEVICE { up | down } 激活| 禁用某接口
show DEVICE
show up : 僅顯示處于激活狀態(tài)的接口
ip address - protocol address management
ip addr { add | del } IFADDR dev STRING
[label LABEL]:添加地址時(shí)指明網(wǎng)卡別名
[scope {global|link|host}]:指明作用域
global: 全局可用;
link: 僅鏈接可用;
host: 本機(jī)可用;
ip address show - look at protocol addresses
[dev DEVICE]
[label PATTERN]
[primary and secondary]
ip address flush - flush protocol addresses
使用格式同show
ip route - routing table management
ip route add
添加路由:ip route add TARGET via GW dev IFACE src SOURCE_IP
TARGET:
主機(jī)路由:IP
網(wǎng)絡(luò)路由:NETWORK/MASK
添加網(wǎng)關(guān):ip route add defalt via GW dev IFACE
ip route delete
刪除路由:ip route del TARGET
ip route show
ip route flush
[dev IFACE]
[via PREFIX]
2.ss命令
格式: ss [options] [ FILTER ]
常用選項(xiàng):
-t : tcp協(xié)議相關(guān)
-u : udp協(xié)議相關(guān)
-w : 顯示裸套接字
-x : unix sock 相關(guān)
-l : 監(jiān)聽狀態(tài)的連接
-a : all
-n : 以數(shù)字格式顯示
-p : 相關(guān)程序及其pid
-e : extend 的信息
-m : 內(nèi)存用量
-o : 計(jì)時(shí)器信息
FILTER := [ state TCP-STATE ] [ EXPRESSION ]
EXPRESSION:
dport =
sport =
補(bǔ)充: tcp的常見狀態(tài)
LISTEN : 監(jiān)聽
EATABLISHED :已建立的連接
FIN_WAIT_1
FIN_WAIT_2
SYN_SENT
SYN_RECV
CLOSE
ss命令跟netstat命令功能相似,但是要當(dāng)前連接數(shù)較大時(shí)用ss命令用著更好。
當(dāng)前名稱:linux網(wǎng)絡(luò)管理及屬性命令
分享鏈接:http://www.rwnh.cn/article16/jisodg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站改版、軟件開發(fā)、ChatGPT、網(wǎng)站策劃、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)