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

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
這是一篇筆記文,每一個 Linux Distribution 的網路設定都不太一樣,最近裝了 Ubuntu Server 18.04 LTS 版 (Cosmic Cuttlefish),網路設定又變得陌生了,Network Manager 改用 netplan (專案網站) 來管理網路設定,改好之後順便上來紀錄一下,不然下次又忘了。 Ubuntu 18.04 設定 netplan 靜態 IP 先看看原本熟悉的 /etc/network/interface 檔案變成什麼樣子: 1 2 3 4 # ifupdown has been replaced by netplan(5) on this system.  See # /etc/netplan for current configuration. # To re-enable ifupdown on this system, you can run: #    sudo apt install ifupdown 照上面的說明看了一下 /etc/netplan 目錄,查閱一下 /etc/netplan/50-cloud-init.yaml,如下: 1 2 3 4 5 6 7 8 9 10 11 12 # This file is generated from information provided by # the datasource.  Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network:     ethernets:         ens192:             dhcp4: true         ens224:             dhcp4: true     version: 2 看來可以關閉 cloud network,但是我其實也沒有要用 cloud-init,乾脆移除它,如下: sudo apt-get remove cloud-init 然後把 /etc/netplan/50-cloud-init.yaml 改成下面這樣: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # This file is generated from information provided by # the datasource.  Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network:     ethernets:         ens192:             addresses: [192.168.32.231/24]             gateway4: 192.168.32.1             nameservers:               addresses: [8.8.8.8,8.8.4.4]             dhcp4: no         ens224:             dhcp4: true     version: 2 這幾年 yaml 深得大眾的心,設定檔就是要用 yaml 格式才是潮,解說一下上述幾個設定: dhcp4: 關閉 DHCP 自動取得 IP,原本是 true 所以改成 no (官方文件竟然不是 false 有點搞笑,但我實際測試 false 也是可以 work 的) addresses: 靜態 IP 與 Mask nameservers: DNS 服務器,可以設定多筆 gateway4: IPv4 所使用的 Gateway 修改後存檔後輸入以下命令: sudo netplan try 這個命令執行後會檢查設定檔格式,如果正確的話就會套用,並且在 120 秒以後自動還原設定! 是不是很貼心?想必各位應該有過把遠端 Linux 網路設定改錯 restart 的痛吧,有了這個設定,至少錯了在兩分鐘以後會還原,不至於讓你的終端機斷線以後就 GG 惹~ 如果測試沒有問題,就可以執行以下命令真正進行設定: sudo netplan apply 就是那麼簡單,下台一鞠躬... Ubuntu 官方參考說明 Configure Static IP Addresses On Ubuntu 18.04 LTS Server 分享到 Twitter(在新視窗中開啟) 按一下以分享至 Facebook(在新視窗中開啟) 分享到 LinkedIn(在新視窗中開啟) 點這裡寄給朋友(在新視窗中開啟) 按一下即可分享至 Skype(在新視窗中開啟) 分享到 Reddit(在新視窗中開啟) 分享到 Tumblr(在新視窗中開啟) 按一下以分享到 Telegram(在新視窗中開啟)

本文由toright提供 原文連結

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