为何无法彻底关闭eth0?

包含网卡/无线网的网络问题和ADSL/校园网/宽带拨号支持及代理/共享等网络使用问题
回复
pengsir
帖子: 137
注册时间: 2015-07-24 8:29
系统: ubuntu

为何无法彻底关闭eth0?

#1

帖子 pengsir »

root@hwy:/home/debian8# ifconfig eth0 down
root@hwy:/home/debian8# route -nv
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
root@hwy:/home/debian8# ifconfig
eth0 Link encap:Ethernet HWaddr e0:3f:49:57:4b:d1
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e23f:49ff:fe57:4bd1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:918 errors:0 dropped:0 overruns:0 frame:0
TX packets:184 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:195407 (190.8 KiB) TX bytes:29304 (28.6 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:496 errors:0 dropped:0 overruns:0 frame:0
TX packets:496 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:728348 (711.2 KiB) TX bytes:728348 (711.2 KiB)

wlan0 Link encap:Ethernet HWaddr 00:21:5d:26:c1:10
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:5dff:fe26:c110/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6556 errors:0 dropped:0 overruns:0 frame:0
TX packets:5709 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3528018 (3.3 MiB) TX bytes:999397 (975.9 KiB)

按照我的理解 eht0对应的ip不可以使用了吧,
奇怪的事情发生了,
root@hwy:/home/debian8# cat /etc/hosts
192.168.1.4 mywp.com

我的本机架设了一个wordpress ,里面说有的url 都是 http://mywp.com/wp/?p=2026 的形式。
eth0明明被关闭了哈 ifconfig eth0 down ,它对应的ip 192.168.1.4不可以使用了哈
为何,我的worpress可以正常在家庭局域网中被其他计算机浏览?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 为何无法彻底关闭eth0?

#2

帖子 poloshiao »

從 Bios 關閉
pengsir
帖子: 137
注册时间: 2015-07-24 8:29
系统: ubuntu

Re: 为何无法彻底关闭eth0?

#3

帖子 pengsir »

请将一下原因,为何需要从bios进行关闭。
为何

ifdown eth0
ifconfig eth0 down
上面的两个语句都不能关闭它,为何?请谈谈原理,我不懂哈。
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 为何无法彻底关闭eth0?

#4

帖子 poloshiao »

ifdown eth0
ifconfig eth0 down
這一些是 軟體關閉
重新開機
lspci 還是會偵測到 eth0 的硬件
還是會被驅動
如果你的設定設定自動
它還是會自動連上線
头像
astolia
论坛版主
帖子: 6703
注册时间: 2008-09-18 13:11

Re: 为何无法彻底关闭eth0?

#5

帖子 astolia »

eth0是正常启用状态RUNNING,ip地址192.168.1.4
ifconfig没能生效可能是驱动问题,也有可能是其他什么东西重新给你启用了
而ifdown默认只能处理通过ifup启动的设备
pengsir
帖子: 137
注册时间: 2015-07-24 8:29
系统: ubuntu

Re: 为何无法彻底关闭eth0?

#6

帖子 pengsir »

4 楼 poloshiao
在这个过程中,不存在这个问题,我一直没有重新开机。

重新開機
lspci 還是會偵測到 eth0 的硬件
還是會被驅動
如果你的設定設定自動
它還是會自動連上線

5 楼 astolia
ifconfig没能生效可能是驱动问题,也有可能是其他什么东西重新给你启用了

还有什么办法利用其他什么命令关闭 eth0?
直接拔网线,eth0彻底关闭了。用什么命令行达到同样效果?或则使eth0重启的东西是什么,如何找出来?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 为何无法彻底关闭eth0?

#7

帖子 poloshiao »

ifdown eth0
ifconfig eth0 down
上面的两个语句都不能关闭它,为何?请谈谈原理,我不懂哈。
在这个过程中,不存在这个问题,我一直没有重新开机。
1. 抱歉 可能我對於你的問題 理解不正確

2. 在 Ubuntu 通常 管理連線 包含 eth0 預裝 兩個機制
2-1. /etc/network/interfaces
2-2. network-manager-gnome 的 NM-Applet

3. 一般預設是在 NM-Applet 設定 eth0 (除非你有改變)
ifup eth0
ifdown eth0
4. 是 管理 /etc/network/interfaces 的連線
所以 管不到 NM-Applet 裡設定 的 eth0

5. 你要把 NM-Applet 裡設定 的 eth0 關閉
滑鼠 朝向 右上方 NM-Applet
按一下 左鍵
再 按一下 斷開
5-1. 如果你發現 斷開 以後 又立刻自動連上線
按一下 編輯連接
把 自動連線 打勾取消
這樣 就不會再自動連上線
5-2. 但是 你希望再連上線 就需要在有線連接上 手動按一下左鍵
5-3. 但是 如果你希望開機就自動連上線 需要把這個自動連線 打勾加上

6. NM-Applet 也可以使用其它指令 啟用/關閉/設定 eth0
但是 一般很少用到 如果有需要 再貼文

7. 進一步參閱
http://askubuntu.com/questions/1786/wha ... g-ifup-etc
What is the difference between Network Manager and 'ifconfig' 'ifup', etc?
pengsir
帖子: 137
注册时间: 2015-07-24 8:29
系统: ubuntu

Re: 为何无法彻底关闭eth0?

#8

帖子 pengsir »

root@hwy:/home/debian8# ifconfig
eth0 Link encap:Ethernet HWaddr e0:3f:49:57:4b:d1
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e23f:49ff:fe57:4bd1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9151 errors:0 dropped:0 overruns:0 frame:0
TX packets:8912 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8117599 (7.7 MiB) TX bytes:1320757 (1.2 MiB)

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:200 errors:0 dropped:0 overruns:0 frame:0
TX packets:200 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:219343 (214.2 KiB) TX bytes:219343 (214.2 KiB)

wlan0 Link encap:Ethernet HWaddr 00:21:5d:26:c1:10
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:5dff:fe26:c110/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:549 errors:0 dropped:0 overruns:0 frame:0
TX packets:52 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:119523 (116.7 KiB) TX bytes:10009 (9.7 KiB)
从这里得到结论:eth0 wlan0 都有ip地址。

root@hwy:/home/debian8# ifconfig eth0 down

我关闭eth0
root@hwy:/home/debian8# ping -c 5 192.168.1.4
PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=0.029 ms
64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.1.4: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.1.4: icmp_seq=4 ttl=64 time=0.033 ms
64 bytes from 192.168.1.4: icmp_seq=5 ttl=64 time=0.019 ms

--- 192.168.1.4 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.019/0.030/0.036/0.006 ms

第一次拼 没有问题
root@hwy:/home/debian8# ping -c 5 192.168.1.4
PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
From 192.168.1.101 icmp_seq=1 Destination Host Unreachable
From 192.168.1.101 icmp_seq=2 Destination Host Unreachable
From 192.168.1.101 icmp_seq=3 Destination Host Unreachable
From 192.168.1.101 icmp_seq=4 Destination Host Unreachable
From 192.168.1.101 icmp_seq=5 Destination Host Unreachable

--- 192.168.1.4 ping statistics ---
5 packets transmitted, 0 received, +5 errors, 100% packet loss, time 4000ms
pipe 4
第二次拼出问题了,都不同。
root@hwy:/home/debian8# ping -c 5 192.168.1.4
PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
From 192.168.1.101 icmp_seq=1 Destination Host Unreachable
From 192.168.1.101 icmp_seq=2 Destination Host Unreachable
From 192.168.1.101 icmp_seq=3 Destination Host Unreachable
64 bytes from 192.168.1.4: icmp_seq=4 ttl=64 time=2010 ms
64 bytes from 192.168.1.4: icmp_seq=5 ttl=64 time=1001 ms

--- 192.168.1.4 ping statistics ---
5 packets transmitted, 2 received, +3 errors, 60% packet loss, time 4024ms
rtt min/avg/max/mdev = 1001.864/1506.213/2010.563/504.350 ms, pipe 3
第三次拼,后两次通了。
root@hwy:/home/debian8# ping -c 5 192.168.1.4
PING 192.168.1.4 (192.168.1.4) 56(84) bytes of data.
64 bytes from 192.168.1.4: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 192.168.1.4: icmp_seq=2 ttl=64 time=0.037 ms
64 bytes from 192.168.1.4: icmp_seq=3 ttl=64 time=0.038 ms
64 bytes from 192.168.1.4: icmp_seq=4 ttl=64 time=0.038 ms
64 bytes from 192.168.1.4: icmp_seq=5 ttl=64 time=0.036 ms

--- 192.168.1.4 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.031/0.036/0.038/0.002 ms
第四次拼,全通了。

什么怪异?用命令行关闭eth0后,th0经历了从不通到通的过程,这是什么原因?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 为何无法彻底关闭eth0?

#9

帖子 poloshiao »

这是什么原因?
eth0 Link encap:Ethernet HWaddr e0:3f:49:57:4b:d1
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
wlan0 Link encap:Ethernet HWaddr 00:21:5d:26:c1:10
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
在 Mask:255.255.255.0 情況下
192.168.1.4, 192.168.1.101 屬於同一個 子網
意思是 你發出的 ping 包 可能跑向 192.168.1.4 也可能 跑向 192.168.1.101

建議
把 wlan0 關閉 再試試看

所以
雙網卡 IP 在同一個子網 同時啟用 可能會壞事
最好讓它 分屬於兩個 不同的 子網
例如
eth0 : 192.168.1.4
wlan0 : 192.168.2.4
是否可行 還要參考你的 dhcp server 的設定要求
回复