[](https://blog.toright.com/?attachment_id=6294) 這是一篇筆記文,每一個 Linux Distribution 的網路設定都不太一樣,最近裝了 Ubuntu Server 18.04 LTS 版 (Cosmic Cuttlefish),網路設定又變得陌生了,Network Manager 改用 [netplan](https://netplan.io/) 來管理網路設定,改好之後順便上來紀錄一下,不然下次又忘了。 ## Ubuntu 18.04 設定 netplan 靜態 IP 先看看原本熟悉的 /etc/network/interface 檔案變成什麼樣子: ``` # 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,如下: ``` # 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 改成下面這樣: ``` # 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](https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/) [原文:Ubuntu 18.04 透過 netplan 設定網路卡 IP](https://blog.toright.com/posts/6293/ubuntu-18-04-%E9%80%8F%E9%81%8E-netplan-%E8%A8%AD%E5%AE%9A%E7%B6%B2%E8%B7%AF%E5%8D%A1-ip.html)
author | samejack |
---|---|
permlink | ubuntu-18-04-netplan-ip |
category | linux |
json_metadata | {"tags":["linux","ubuntu","cn","esteem-cn","cn-curation"],"image":["https://blog.toright.com/wp-content/uploads/2019/02/ubuntu-18.10-codename-.jpg"],"links":["https://blog.toright.com/?attachment_id=6294","https://netplan.io/","https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/","https://blog.toright.com/posts/6293/ubuntu-18-04-%E9%80%8F%E9%81%8E-netplan-%E8%A8%AD%E5%AE%9A%E7%B6%B2%E8%B7%AF%E5%8D%A1-ip.html"],"app":"steemit/0.1","format":"markdown"} |
created | 2019-02-23 05:38:30 |
last_update | 2019-02-23 05:38:30 |
depth | 0 |
children | 2 |
last_payout | 2019-03-02 05:38:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.046 HBD |
curator_payout_value | 0.013 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,627 |
author_reputation | 110,019,617,866 |
root_title | "Ubuntu 18.04 透過 netplan 設定網路卡 IP" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 80,271,359 |
net_rshares | 105,008,812,894 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
justyy | 0 | 46,821,311,890 | 2.11% | ||
superbing | 0 | 719,627,876 | 7.68% | ||
dailystats | 0 | 2,158,155,223 | 7.67% | ||
jianan | 0 | 1,171,761,324 | 7.43% | ||
cnbuddy | 0 | 11,702,903,752 | 1% | ||
anxin | 0 | 119,600,543 | 7.43% | ||
woolfe19861008 | 0 | 95,258,299 | 7.43% | ||
dailychina | 0 | 2,038,929,945 | 7.68% | ||
dongfengman | 0 | 652,313,055 | 7.43% | ||
ethanlee | 0 | 183,544,263 | 6.44% | ||
lilypang22 | 0 | 152,064,735 | 7.04% | ||
sweet-jenny8 | 0 | 1,284,266,097 | 7.43% | ||
laiyuehta | 0 | 261,504,899 | 7.43% | ||
turtlegraphics | 0 | 713,177,414 | 7.64% | ||
sbi7 | 0 | 35,092,146,167 | 37.07% | ||
witnesstools | 0 | 685,812,024 | 7.65% | ||
ahmedjony | 0 | 0 | 5% | ||
bestboutique6 | 0 | 5,576,753 | 5% | ||
ilovecoding | 0 | 680,907,104 | 7.64% | ||
steemfuckeos | 0 | 431,990,240 | 7.64% | ||
samejack | 0 | 37,961,291 | 100% |
你那里天气如何?想要参加活动但是不知道从何开始?关注寻宝团@cn-activity每日整理社区活动!假如我的留言打扰到你,请回复“取消”。
author | cnbuddy |
---|---|
permlink | re-samejack-ubuntu-18-04-netplan-ip-20190223t060320118z |
category | linux |
json_metadata | "" |
created | 2019-02-23 06:03:21 |
last_update | 2019-02-23 06:03:21 |
depth | 1 |
children | 0 |
last_payout | 2019-03-02 06:03:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 69 |
author_reputation | -1,449,160,991,441 |
root_title | "Ubuntu 18.04 透過 netplan 設定網路卡 IP" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 80,272,035 |
net_rshares | 0 |
Congratulations @samejack! You received a personal award! <table><tr><td>https://steemitimages.com/70x70/http://steemitboard.com/@samejack/birthday1.png</td><td>Happy Birthday! - You are on the Steem blockchain for 1 year!</td></tr></table> <sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@samejack) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=samejack)_</sub> ###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
author | steemitboard |
---|---|
permlink | steemitboard-notify-samejack-20191101t102527000z |
category | linux |
json_metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
created | 2019-11-01 10:25:27 |
last_update | 2019-11-01 10:25:27 |
depth | 1 |
children | 0 |
last_payout | 2019-11-08 10:25:27 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 619 |
author_reputation | 38,975,615,169,260 |
root_title | "Ubuntu 18.04 透過 netplan 設定網路卡 IP" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 92,099,163 |
net_rshares | 0 |