使用靜態 IP 時網際網路無法運作。目前沒有有效的解決方案

使用靜態 IP 時網際網路無法運作。目前沒有有效的解決方案

Ifconfig返回以下內容:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.39  netmask 255.255.255.0  broadcast 192.168.1.255
    inet6 fe80::a00:27ff:fefa:258e  prefixlen 64  scopeid 0x20<link>
    ether 08:00:27:fa:25:8e  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 20  bytes 1368 (1.3 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我的etc/network/interfaces看起來像這樣:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

auto eth0
iface eth0 inet static
address 192.168.1.39
netmask 255.255.255.0
gateway 192.168.1.1

Route -n返回以下內容:

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 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

我正在使用以下 DNS:

domain **
search **
nameserver 172.139.62.5
nameserver 8.8.8.8

(星星隱藏了我的本地 DNS,我寧願不公開)

使用非靜態 IP 確實有效。我在虛擬機器中運行 Linux。

答案1

您使用的網關位址似乎與192.168.1.1您的路由器位址不符。如果您使用靜態 IP 尋址,則詳細資訊與您的網路非常匹配,否則它將無法運作。

從路由器的 IP 位址開始。可能是 192.168.1.254。可能是 10.11.12.13。它可能完全是另一回事。

然後,您需要再次從路由器設定中取得網路掩碼,該遮罩可以是 24 或類似 255.255.255.0 的值。

對於網路遮罩中的每個 255,您需要從路由器的 IP 位址複製對應的數字。因此,三批 255 意味著您複製前三組數字。 (如果您只有一個數字網路掩碼,例如 24,請將其除以 8,結果將給出您必須複製的數字的計數。)最後,您需要分配未使用的值,以便最終獲得四組數字。

假設您的路由器是 10.1.1.254,網路遮罩是 255.255.0.0。然後你複製 10.1 並得出 1-254 範圍內的剩餘兩個數字。結果是您的 IP 位址,例如 10.1.44.66,但不要使用已在使用的號碼組!

相關內容