Linux

在linux中關閉網路介面的正確方法

  • September 14, 2021

例如:

$ ifconfig dummy0 up
$ ifconfig dummy0 "192.168.1.190 netmask 255.255.255.0"

不帶參數呼叫ifconfig顯示界面

dummy0    Link encap:Ethernet  HWaddr b6:1f:f3:92:6d:20  
     inet addr:192.168.1.190  Bcast:192.168.1.255  Mask:255.255.255.0
     inet6 addr: fe80::b41f:f3ff:fe92:6d20/64 Scope:Link
     UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
     RX packets:0 errors:0 dropped:0 overruns:0 frame:0
     TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:0 
     RX bytes:0 (0.0 B)  TX bytes:1050 (1.0 KiB)

如何關閉界面以使其不顯示

  • 如果配置
  • ifconfig -a
  • ifconfig 虛擬0

沒有 rmmod 假人

因為 dummy 僅用於範例目的。

如果沒有辦法做到這一點,我可以為它設置什麼“丟棄”IP並避免任何麻煩?

喜歡

$ ifconfig dummy0 down
$ ifconfig dummy0 0.0.0.0

刷新ip:

root@foo:~# ifconfig dummy0 192.168.55.1 netmask 255.255.255.0
root@foo:~# ifconfig dummy0 
dummy0    Link encap:Ethernet  HWaddr 5b:72:32:4f:92:c8  
         inet addr:192.168.55.1  Bcast:192.168.55.255  Mask:255.255.255.0
         UP BROADCAST RUNNING NOARP  MTU:1500  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)

root@foo:~# ip address flush dev dummy0
root@foo:~# ifconfig dummy0 down
root@foo:~# ifconfig dummy0 
dummy0    Link encap:Ethernet  HWaddr 5b:72:32:4f:92:c8
         BROADCAST NOARP  MTU:1500  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)

引用自:https://serverfault.com/questions/34899