3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
以往在 Ubuntu 下設定 IP 的方式為修改 /etc/network/interfaces,而 Ubuntu 從 17.10 版開始使用 Netplan 作為系統預設的網路設定方式,設定上較容易理解,而管理性也相對地提升了不少(尤其是在雲端環境)。 首先執行 ls -al /etc/netplan 看看是否已有設定檔存在。 [email protected]:~$ ls -al /etc/netplan total 12 drwxr-xr-x 2 root root 4096 May 3 08:50 ./ drwxr-xr-x 95 root root 4096 May 29 00:15 ../ -rw-r--r-- 1 root root 116 May 3 08:50 00-installer-config.yam 確認一下內容,通常在安裝時沒有特別設定的話會產生一個 DHCP 的設定檔,其內容如下: [email protected]:~$ cat /etc/netplan/00-installer-config.yaml # This is the network config written by 'subiquity' network: ethernets: ens33: dhcp4: true version: 2 直接以新的內容取代它,要設定的固定 IP 為 192.168.1.220,閘道 (分享器、路由器、小烏龜等) 為 192.168.1.1,DNS 直接套用閘道的設定,因此給相同的 IP。 echo 'network: version: 2 ethernets: ens33: addresses: - 192.168.1.220/24 gateway4: 192.168.1.1 nameservers: addresses: - 192.168.1.1 ' | sudo tee /etc/netplan/00-installer-config.yaml 執行 sudo netplan try 套用設定,這時候通常會斷線個幾秒鐘,之後終端機上就會出現一個倒數計時,代表設定正確。這時候再按下 Enter 就會保存設定。 [email protected]:~$ sudo netplan try Warning: Stopping systemd-networkd.service, but it can still be activated by: systemd-networkd.socket Do you want to keep these settings? Press ENTER before the timeout to accept the new configuration Changes will revert in 118 seconds Configuration accepted. [email protected]:~$ 如果設定錯誤的話就會斷線,但是不用擔心,倒數 120 秒後如果沒有按下 Enter,系統就知道設定錯誤,導致你無法做最後的確認動作,系統就會恢復套用前的網路設定。這時候可以再登入進去修正。 References: Netplan | Backend-agnostic network configuration in YAML Ubuntu Bionic: Netplan | Ubuntu 請按讚: 喜歡 正在載入...

本文由caloskaoorg提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦