[網絡配置相關]——ifconfig命令、ip命令、route命令


ifconfig命令

1. 查看已被激活的網卡的詳細信息

# ifconfig 
eth0 Link encap:Ethernet HWaddr 00:30:67:F2:10:CF 
inet addr:10.0.0.253 Bcast:10.0.255.255 Mask:255.255.0.0
inet6 addr: fe80::230:67ff:fef2:10cf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4663517 errors:0 dropped:0 overruns:0 frame:0
TX packets:6122850 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:1852734274 (1.7 GiB) TX bytes:1487018040 (1.3 GiB)

HWaddr :網卡的硬件地址,即MAC地址

inet addr:IPv4的IP 地址
Bcast:廣播地址
mask:子網掩碼
inet6 addr:IPv6地址
MTU:最大傳輸單元
Metric:用於計算路由的成本
RX:表示網絡啟動到現在的封包接受情況 (Receive)
packets:表示接包數
errors:表示接包發生錯誤的數量
dropped:表示丟棄的包數量
overruns:表示接收時因過速而丟失的數據包數
frame:表示發生frame錯誤而丟失的數據包數
TX:從網絡啟動到現在傳送的情況 (Transmit)
collisions:沖突信息包的數目
txqueuelen:發送隊列的大小
RX byte、TX byte:總傳送/接受的量

注:由RX和TX可以了解網絡是否非常繁忙
注:errors:0 dropped:0 overruns:0 frame:0,都為0 說明網絡比較穩定
注:collisions發生太多次表示網絡狀況不太好

2. 臨時IP配置 

# ifconfig eth0 172.16.0.118 netmask 255.255.0.0
# ifconfig eth0 172.16.0.118/16
# ifconfig eth0:1 172.16.0.119/16  指定子接口

3. 配置臨時MAC地址(配置文件中的mac地址不可直接改,要不就不寫) 

# ifconfig eth0 hw ether B8:97:5A:00:4E:3A 

4. 簡單的啟動和關閉網絡接口

# ifdown eth0 ; ifup eth0

5. 關閉臨時的網絡接口

# ifconfig eth0:1 down

6. 啟用和關閉arp協議

# ifconfig eth0  arp
# ifconfig eth0  -arp

7. 設置傳輸單元mtu的值

# ifconfig  eth0  mtu  1000

ip命令

1. 關於額外IP的相關設定:ip add 臨時增加/刪除IP地址

# ip add add 192.168.1.126/24  dev eth0:0  
# ip add del  192.168.1.126/24  dev eth0:0
# ip add  show
# ip add  show eth0

2. 關於接口設備的相關設置:ip link

# ip link set eth0 up        //開啟網卡
# ip link set eth0 down      //關閉網卡
# ip link set eth0 name lyj  //網卡改名
# ip link set eth0 mtu 1000  //改mtu值
# ip link show   //顯示所有接口信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:d6:81:26 brd ff:ff:ff:ff:ff:ff

# ip -s link show eth0  //顯示接口流量信息
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:d6:81:26 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    107193541  1118624  0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    116799818  1093559  0       0       0       0

# ip -s -s link show eth0  //多一個-s表示更詳細的信息
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:d6:81:26 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    107031087  1116940  0       0       0       0
    RX errors: length  crc     frame   fifo    missed
               0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    116526036  1091941  0       0       0       0
    TX errors: aborted fifo    window  heartbeat
               0        0       0       0

3. 關於路由的相關設置:ip route

# ip route show  //查看路由信息
10.0.0.0/16 dev eth0  proto kernel  scope link  src 10.0.10.158 
169.254.0.0/16 dev eth0  scope link  metric 1002 
default via 10.0.0.254 dev eth0 

# ip route add 10.10.10.0/24 via 172.16.0.254  dev eth0  //添加一條路由
# ip route del 10.10.10.0/24                             //刪除一條路由

# ip route add default via 172.16.0.254  dev eth0     //添加默認路由
# ip route del default  via 172.16.0.254   dev eth0   //刪除默認路由

4. 其他

# ip monitor all   //所在局域網的一台電腦根據它的狀態可以被分類成REACHABLE或者STALE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff STALE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff REACHABLE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff STALE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff REACHABLE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff STALE
[NEIGH]10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff REACHABLE

# ip neighbour  //查看接入你所在的局域網的設備的MAC地址
10.104.64.1 dev eth0 lladdr fe:ee:ff:ff:ff:ff REACHABLE

  


route命令  

1. 查看路由狀態

# route  -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.104.64.0     0.0.0.0         255.255.192.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         10.104.64.1     0.0.0.0         UG    0      0        0 eth0

Destination:目的地
Genmask:路由的網絡掩碼
Gateway:該網絡通過哪個網關連接出去的(下一跳)
      0.0.0.0:表示路由直接由本機傳送,即局域網的MAC直接發送的
      IP:表示該路由需要路由器(網關)的轉發才能發送
Flags:標志
      U Up表示此路由當前為啟動狀態
      H Host,表示此網關為一主機
      G Gateway,表示此網關為一路由器
      R Reinstate Route,使用動態路由重新初始化的路由
      D Dynamically,此路由是動態性地寫入
      M Modified,此路由是由路由守護程序或導向器動態修改
      ! 表示此路由當前為關閉狀態
Iface:這個路由傳遞數據包的接口 

2.增刪/設置路由

# route add -net  172.16.0.0/16  netmask 255.255.0.0  gw 172.16.0.254  dev eth0    //增加一條路由 -net后面接的路由為一個網絡
# route del  -net  172.16.0.0/16  netmask 255.255.0.0  gw 172.16.0.254  dev eth0   //刪除一條路由
# route  add  -host  172.16.10.10 gw 192.168.1.1   //-host連接到單部主機的路由
# route  add  default  gw  192.168.1.1             //增加默認路由 gw指定下一跳  
# route  del   default  gw 192.168.1.1  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM