linux網(wǎng)絡(luò)管理及屬性命令-創(chuàng)新互聯(lián)

一.Linux網(wǎng)絡(luò)管理命令

成都創(chuàng)新互聯(lián)公司-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比旌陽(yáng)網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式旌陽(yáng)網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋旌陽(yáng)地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴(lài)。

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:?jiǎn)⒂煤罅⒓瓷?。再次開(kāi)機(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īng)的套接字     //常跟-t,-u選項(xiàng)

  -p :打印信息

  -e :擴(kuò)展信息

  -n :以數(shù)字形式顯示

  -p: 顯示相關(guān)pid信息

Eg:以數(shù)字形式顯示當(dāng)前主機(jī)下tcp協(xié)議都監(jiān)聽(tīng)那些端口并打印出來(lái)
[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īng)狀態(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的常見(jiàn)狀態(tài)

   LISTEN  : 監(jiān)聽(tīng)

   EATABLISHED :已建立的連接

   FIN_WAIT_1

   FIN_WAIT_2

   SYN_SENT

   SYN_RECV

   CLOSE

ss命令跟netstat命令功能相似,但是要當(dāng)前連接數(shù)較大時(shí)用ss命令用著更好。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

當(dāng)前題目:linux網(wǎng)絡(luò)管理及屬性命令-創(chuàng)新互聯(lián)
文章分享:http://muchs.cn/article46/cochhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、定制開(kāi)發(fā)、網(wǎng)站策劃ChatGPT、App設(shè)計(jì)網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司