安裝 Ubuntu Server 的一些初始網路設定

Written by Simon Asika on

平時太習慣 VPS 設定好的環境,剛安裝完單機版 Ununtu 之後就是連不上網路,不過內網連的好好的。希望將主機當成伺服器的使用者需要記得先做幾項設定,讓網路暢通。

設定靜態 IP

輸入以下指令編輯網路設定:

$ sudo vim /etc/network/interface

改成如下設定

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

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 140.112.xxx.xxx  # Your IP
netmask 255.255.255.0    # Mask
gateway 140.112.xxx.xxx  # Gatway

接著輸入以下指令重啟網路:

$ sudo service network-manager restart

$ sudo /etc/init.d/networking restart

現在你就可以依照固定IP連限制主機了。

設定路由

接著你會發現只有內網的機器可以連上主機,往外無論 Apache 還是 ssh 都連不上。如果我們在主機上 ping 網外 IP ,會出現 connect:network is unreachable 的訊息。

此時是因為 Default Route 還沒設定,請輸入以下指令:

$ route add default gw 140.112.xxx.xxx # 等同 Gatway

接著再度 Restart 網路設定即可:

$ sudo /etc/init.d/networking restart

Control Tools

WS-logo