- 取得連結
- X
- 以電子郵件傳送
- 其他應用程式
Ubuntu 在 17.10 的版本網路設定改使用 netplan 套件,修改 /etc/network/interfaces 不會有反應
本文章撰寫參考至下方參考資料之網站與 netplan 官網範例文件請前往下方參考資料檢視
此環境 Ubuntu 作業系統資訊
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
netplan 的網路設定路徑在 /etc/netplan 資料夾底下,名稱為 01-netcfg.yaml
此環境預設 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
eth0 網路介面開啟 DHCP IPv4 設定
調整網路設定為靜態 IP 位址
透過文字編輯器將 01-netcfg.yaml 修改為靜態 IP 位址
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [192.168.0.80/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.4.4]
簡短說明:關閉 DHCP 功能,設定 IP 位址為 192.168.0.80,/24 為子網路遮罩,預設閘道為 192.168.0.1,DNS 伺服器為 8.8.4.4
編輯完成後使用下面指令變更網路設定
sudo netplan apply
檢查網路設定
使用 ifconfig 指定查看設定結果
eth0: flags=4163 mtu 1500
inet 192.168.0.80 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::215:5dff:fe00:14d4 prefixlen 64 scopeid 0x20
ether 00:15:5d:00:14:d4 txqueuelen 1000 (Ethernet)
RX packets 2488 bytes 1506519 (1.5 MB)
RX errors 0 dropped 187 overruns 0 frame 0
TX packets 782 bytes 79091 (79.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 31 bytes 2572 (2.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31 bytes 2572 (2.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
使用 ping 指令確認 DNS 伺服器設定
root@(SERVERNAME):/# ping www.google.com.tw
PING www.google.com.tw (172.217.27.131) 56(84) bytes of data.
64 bytes from tsa03s02-in-f131.1e100.net (172.217.27.131): icmp_seq=1 ttl=54 time=10.9 ms
64 bytes from tsa03s02-in-f131.1e100.net (172.217.27.131): icmp_seq=2 ttl=54 time=11.5 ms
^C
--- www.google.com.tw ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 10.964/11.250/11.536/0.286 ms
留言
張貼留言