Ff *_*ote 1 networking 12.04 static-ip
我将服务器的 ip 从动态更改为静态。使用以下代码更改 /etc/network/interfaces 中的文件后,我的服务器失去了与互联网的连接。
Here's my new network interfaces:
auto eth0
iface eth0 inet static
address 192.168.254.120
netmask 255.255.255.0
network 192.168.254.0
broadcast 192.168.254.255
gateway 192.168.254.1
Run Code Online (Sandbox Code Playgroud)
所以之后,我重新启动网络服务,我在 ifconfig 中的 ip 更改为 192.168.254.120,但是当我尝试 ping 任何站点或我的其他电脑时,它不起作用。我将把我的原始 ifconfig 信息放在这里,以防有人问。
ifconfig
eth0
inet addr: 192.168.254.109
Bcast: 192.168.254.255
Mask: 255.255.255
Run Code Online (Sandbox Code Playgroud)
我希望有人可以帮助我将我的服务器更改为静态 ip。谢谢。
我建议使用以下 /etc/network/interfaces 文件:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.254.120 #assuming this address is outside the range used for DHCP in the router
netmask 255.255.255.0
gateway 192.168.254.1
dns-nameservers 8.8.8.8 192.168.254.1
Run Code Online (Sandbox Code Playgroud)
现在让系统读取和使用更改:
sudo ifdown eth0 && sudo ifup eth0
Run Code Online (Sandbox Code Playgroud)
检查您是否可以访问互联网:
ping -c3 www.google.com
Run Code Online (Sandbox Code Playgroud)