如何使用 ifconfig 變更本機網路資訊(ip、網路遮罩、廣播)

如何使用 ifconfig 變更本機網路資訊(ip、網路遮罩、廣播)

我正在使用 Kali Linux (2019.1a) 和 VirtualBox 來閱讀這本書Linux Basics for Hackers (No Starch Press, 2018),當更改我的網路資訊(第 3 章)時,我無法再存取網路。

這是我所做的:

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe77:94b  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:77:09:4b  txqueuelen 1000  (Ethernet)
        RX packets 15771  bytes 18253966 (17.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4016  bytes 243513 (237.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 20  bytes 1116 (1.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20  bytes 1116 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ ping google.com
PING google.com (172.217.25.142) 56(84) bytes of data.
64 bytes from syd15s03-in-f14.1e100.net (172.217.25.142): icmp_seq=1 ttl=63 time=23.10 ms
64 bytes from syd15s03-in-f14.1e100.net (172.217.25.142): icmp_seq=2 ttl=63 time=23.4 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1ms
rtt min/avg/max/mdev = 23.351/23.655/23.959/0.304 ms
$ # Change IP from 10.0.2.15 to 10.0.2.21
$ ifconfig eth0 10.0.2.21 netmask 255.255.255.0 broadcast 10.0.2.255
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.21  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe77:94b  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:77:09:4b  txqueuelen 1000  (Ethernet)
        RX packets 230432  bytes 263807948 (251.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 58741  bytes 3535449 (3.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 20  bytes 1116 (1.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20  bytes 1116 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ ping google.com
ping: google.com: Name or service not known

我仔細檢查了書中的命令,我所做的一切似乎都很匹配。

如何更改我的網路資訊而不終止我的網路/網路存取?

答案1

不要在遠端會話中嘗試此操作!


當更改 eth0 的 IP 位址(這也是您的介面)時default route,您也必須更改它。

像這樣的事情:

# ifconfig eth0 down
# route del default
# ifconfig eth0 10.0.2.21 netmask 255.255.255.0 broadcast 10.0.2.255
# route add default eth0

這是憑記憶得出的,因此您可能需要查閱線上幫助頁

相關內容