IPv4 是互聯網基石協議。在 Ubuntu 中配置 IPv4 主要編輯 /etc/network/interfaces(IP、閘道、子網掩碼)與 /etc/resolv.conf(DNS)。以下提供四種常見場景的設定範例。

sudo vi /etc/network/interfaces
# 替換 eth0 相關行
auto eth0
iface eth0 inet dhcp
sudo /etc/init.d/networking restart
# 或直接執行
sudo dhclient eth0
sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
#network 192.168.3.0
#broadcast 192.168.3.255
sudo /etc/init.d/networking restart
sudo vi /etc/network/interfaces
auto eth0:1
iface eth0:1 inet static
address 192.168.1.60
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x
sudo /etc/init.d/networking restart
編輯 /etc/resolv.conf:
nameserver 192.168.3.2
亦可在 /etc/hosts 加入靜態主機名對應。修改後重啟網路服務即可生效。