Ubuntu 禁用 Netplan 而改用 ifupdown 配置网络

Kevin 教程 9,298 次浏览 108条评论

安装 Ubuntu Server 18.04 后发现网络配置方法有了变化,由原来的 ifupdown 改为了 Netplan。虽然网上可以轻易找到 Netplan 配置教程,如 Linode 这个更详细官方文档,但对于需要沿用 ifupdown 的场景就会带来障碍。下面介绍如何禁用 Netplan 改回 ifupdown,并将默认 DNS 管理由 systemd-resolved 改回 resolvconf。

系统安装时设置

Netplan FAQ 里有提到,可以在系统安装时设置不用 Netplan(引导界面按 F6 键设置如下参数)。

netcfg/do_not_use_netplan=true

该方法似乎只在实体机上具操作性,用 VNC 和 VirtualBox 测试按 F6 没反应。网上查询说因安全原因拦截了部分按键,没有找到可行解决办法。试了几个 VNC 客户端和修改 ISO 镜像文件设置均无解。

系统安装后设置

下面操作如非 root 用户请在命令前加sudo。过程中需仔细检查确认,弄错了会丢失网络连接。

1. 安装 ifupdown、resolvconf 软件包。

apt install ifupdown resolvconf

2. 修改/etc/network/interfaces文件配置网络连接。

如设置 DHCP 网络(修改其中网卡名称。如要使用 eth0 经典命名方式,该文曾有介绍)。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

或设置静态网络(其中 DNS 语句如果不改回 resolvconf 将不会起作用,而需要在 systemd-resolved 所属的/etc/systemd/resolved.conf配置文件里设置)。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address xxx.xxx.xxx.xxx
        netmask xxx.xxx.xxx.xxx
        gateway xxx.xxx.xxx.xxx
        dns-nameservers 8.8.8.8 8.8.4.4

3. 关闭 & 重开网络接口,设置networking服务开机启动和重启使设置生效。

ifdown --force eth0 lo && ifup -a
systemctl enable networking
systemctl restart networking

之后可通过systemctl status networking检查是否设置成功。

4. 停止、取消和禁止 Netplan 相关服务运行,并移除 Netplan 软件包及其配置文件。

解释下所操作的服务:

  • networkd-dispatcher是 Netplan 后端服务(桌面版则是NetworkManager);
  • networkd-dispatcher是 Netplan 守护服务,可通过监听连接状态以执行特定事件操作;
  • systemd-networkd-wait-online用于检测systemd-networkd所管理网络接口的连接状态;
  • systemd-resolved新的 DNS 管理服务,其配置文件里有的参数依赖 Netplan 后端服务工作;
systemctl stop systemd-networkd networkd-dispatcher systemd-networkd-wait-online systemd-resolved
systemctl disable systemd-networkd networkd-dispatcher systemd-networkd-wait-online systemd-resolved
systemctl mask systemd-networkd networkd-dispatcher systemd-networkd-wait-online systemd-resolved
apt purge nplan netplan.io

后续如要切换回 Netplan,别忘了恢复上述系统服务。将带有 mask 的命令换成 unmask 运行一次,不然即使 start  disable 了也没法使用服务。

其它可能用到的命令扩展:

  • systemctl list-dependencies systemd-networkd --reverse查询指定服务所关联的依赖项;
  • systemctl list-unit-files --type=masked --all列出/lib/systemd/system下被禁止的服务;

6. 完成以上操作就设置完成了,全文实测在 Ubuntu Server 18.04 系统下通过。

如果 DNS 解析不了,请检查/etc/resolv.conf所链接的文件是否是/run/resolvconf/resolv.conf。如果不是,运行下面命令设置。

ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    Hello, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can recommend? I get so much lately it’s driving me crazy so any support is very much appreciated.|

    https://vbucks.press/

  3. #3

    hydroxychloroquine use for fibromyalgia https://hydroxychloroquine.webbfenix.com/

  4. #4

    dapoxetine tablets for sale https://salemeds24.wixsite.com/dapoxetine

  5. #5

    ivermectin cost per pill https://ivermectin.webbfenix.com/

  6. #6

    ivermectin tablets for humans for sale https://ivermectin.mlsmalta.com/

  7. #7

    studies show hydroxychloroquine works https://hydroxychloroquine.mlsmalta.com/

  8. #8

    cialis headache jocialisrl http://www.lm360.us/

  9. #9

    vidalista 40 mg for sale https://vidalista.mlsmalta.com/

  10. #10

    hydroxychloroquine for sale india https://hhydroxychloroquine.com/

  11. #11

    is generic viagra as good http://droga5.net/

  12. #12

    tamoxifen dose breast cancer https://tamoxifen.mrdgeography.com/

  13. #13

    how does ivermectin work https://ivermectin1st.com/

  14. #14

    cost of aurogra at costco https://aurogra.buszcentrum.com/

  15. #15

    sildenafil and dapoxetine dosage https://ddapoxetine.com/

  16. #16

    cvs pharmacy refill online https://medpills.bee-rich.com/

  17. #17

    cvs pharmacy refill online https://buymeds.mlsmalta.com/

  18. #18

    80mg vidalista strengths https://vidalista40mg.mlsmalta.com/

  19. #19

    tadalafil for high blood pressure https://wisig.org/

  20. #20

    cost of albuterol sulfate solution https://amstyles.com/

  21. #21

    loan lenders

  22. #22

    bbw cams

  23. #23

    low rate personal loan

  24. #24

    dexamethasone 75 mg

  25. #25

    buy zentiva hydroxychloroquine https://hydroxychloroquinee.com/

  26. #26

    cam fuze

  27. #27

    online female viagra

  28. #28

    levitra 80 mg

  29. #29

    hydroxychloroquine 40 mg

  30. #30

    ivermectin humans

  31. #31

    where to buy cialis in singapore

  32. #32

    universal property insurance

  33. #33

    oct plaquenil toxicity images https://hydroxychloroquine.wisig.org/

  34. #34

    oct plaquenil toxicity images https://hydroxychloroquine.lm360.us/

  35. #35

    You have mentioned very interesting points! ps nice web site. “Justice is the truth in action.” by Jeseph Joubert.

    http://www.vreyrolinomit.com/

  36. #36

    In fact, nearly all high one hundred apps by client spend have a subscription choice.

    Take a look at my blog post; free robux generator

  37. #37

    Here, we’re talking about essentially the most promising and the popular languages for game localization in 2021.

    Also visit my webpage 吸雞巴

  38. #38

    The age group represents a mere 14.2% of mobile gamers, whereas folks older
    than forty five years make up practically a 3rd.

    Feel free to surf to my homepage: among us hack download

  39. #39

    Plus, you can play with individuals on PS4, iOS, and PC as nicely.

    My blog post; Roblox darmowy robux

  40. #40

    rxtoed generic for cialis http://cialllis.com/

  41. #41

    Noodlecake Studios also does Alto’s Adventure, the predecessor to this one.

    Take a look at my web blog – 迪克情人

  42. #42

    Overall, the Battle of Polytopia is simply an effective way to get your strategy gaming fix on cell.

    Also visit my web blog https://chrome.google.com/webstore/detail/jgicjkljgilpgnnmjdajdfemfglnlcop

  43. #43

    The game fuses a pixelated artwork fashion with pop culture references to
    create a enjoyable and fascinating gaming experience.

    my webpage: mobile games

  44. #44

    Nice post. I was checking continuously this blog and I am impressed!
    Extremely helpful info particularly the last part 🙂 I care for such
    info a lot. I was seeking this particular info for a very long time.

    Thank you and good luck.

    My blog – top 10 mobile games to play with friends

  45. #45

    tadalafil canadian pharmacy online https://cialis.cleckleyfloors.com/

  46. #46

    tadalafil canadian pharmacy online https://cialis.studiowestinc.com/

  47. #47

    alex9393939393 alex9393939393 alex9393939393 alex9393939393

  48. #48

    Monument Valley is likely one of the prettiest puzzle games in existence — and one of many
    prettiest games available in any genre, really.

    Look into my blog – https://issuu.com/

  49. #49

    ng Goes On In Our Tool So We Would Like To Verify That You Are

  50. #50

    owers & likes with TikTokFollowersFree & become TikTok famous

  51. #51

    ss of Getting Free Followers and Likes? Head to our free software. Add in your

  52. #52

    All you have to do is enter in your username associated with your TikTok account, select the amount of followers you

  53. #53

    Coin Master Triche et Astuce – Comment avoir illimité Pièces et Tours sur Coin Master – Triche Astuce en Ligne

  54. #54

    ble option and not just that, it can be. Want some free spins and coins in Coin Master

  55. #55

    begging, type your username. Connect the account by pressing the bottom “Get Followers”. Choose the number of the fans and likes you want

  56. #56

    ligne de cigarettes! Notre site web a été lancé pour donner aux fumeurs la g

  57. #57

    Among Us is the game on all of your minds so lets look at what the Among Us Mod Menu apk has to offer us. Find out more! Among us hack

  58. #58

    All skins unlocked, always imposter mod. Use this hack mod to play Among US Hack Mod Menu with

  59. #59

    please fax or e-mail Check `n Go your latest pay stub when applying to ensure timely processing of your loan

  60. #60

    free tiktok followers

  61. #61

    This generator allows users to get free tiktok followers completely for free.

  62. #62

    HOW TO GET COIN MASTER FREE SPINS 2021: Apart from just taking the daily links above

  63. #63

    will get 5 spins from coin master. You can get 40 spins

  64. #64

    I am sure this post has touched all the internet visitors,
    its really really pleasant post on building up new
    webpage. http://antiibioticsland.com/Cipro.htm

  65. #65

    coin master free spins

  66. #66

    This game, the one which lit the world on fireplace for
    a summer season, nonetheless has a surprisingly giant
    variety of hardcore followers.

    Here is my website – free robux generator

  67. #67

    What software program growth platform / tool or engine do you use to build your games?

    my web blog; roblox robux hack

  68. #68

    use Roblox Generator to add Unlimited Robux to your Roblox account. This is the official Roblox Robux Generator updated for 2020. Generator is easy to use.

  69. #69

    so it demands heavy security to generate Robux. There are many spurious websites or pages which are already

  70. #70

    LAIM YOUR ROBUX PACKAGE BY FILLING OUT THE FOR

  71. #71

    o it demands heavy security to generate

  72. #72

    Hello, this weekend is good in support of me, as this
    moment i am reading this fantastic educational paragraph here at my residence. http://herreramedical.org/chloroquine

  73. #73

    blox unlimited robux and tix roblox robux hack script pastebin how to get

  74. #74

    re de vous un bien meilleur joueur. Si vous n’avez pas encore utilisé l

  75. #75

    order cialis online http://edbuy.online/

  76. #76

    Only a smiling visitant here to share the love (:, btw great design. “The price one pays for pursuing a profession, or calling, is an intimate knowledge of its ugly side.” by James Arthur Baldwin.

    http://www.zortilonrel.com/

  77. #77

    Howdy! Someone in my Facebook group shared this website with us so I
    came to take a look. I’m definitely enjoying the information.
    I’m bookmarking and will be tweeting this to my followers!
    Excellent blog and terrific design. http://antiibioticsland.com/Amoxil.htm

  78. #78

    This is very interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your great post. Also, I’ve shared your web site in my social networks!

    https://alansolarsh.shutterfly.com/

  79. #79

    Greetings from Idaho! I’m bored at work so I decided to check out your site on my iphone during lunch break. I really like the info you provide here and can’t wait to take a look when I get home. I’m amazed at how fast your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyhow, superb blog!

    http://www.vreyrolinomit.com/

  80. #80

    As I website possessor I conceive the subject matter here is really good, thanks for your efforts.

    http://www.zortilonrel.com/

  81. #81

    Tadalafil rezeptfrei bestellen tadalafil farmacodinamia
    tadalafil for altitude sickness

  82. #82

    Cymbalta viagra generic canadian pharmacy rx online

  83. #83

    Have you ever heard of second life (sl for short). It is basically a online game where you can do anything you want. sl is literally my second life (pun intended lol). If you would like to see more you can see these second life articles and blogs

    edugamesresearch.com/blog/category/business-games/page/7/

  84. #84

    Have you ever heard of second life (sl for short). It is essentially a video game where you can do anything you want. SL is literally my second life (pun intended lol). If you want to see more you can see these Second Life articles and blogs

    wiki.jokaydia.com/index.php?title=Enetworks07_eventdocumentation&oldid=721

  85. #85

    Comprar generico levitra en españa personal experience with levitra ingredients in levitra

  86. #86

    Canada drugs online canadian pharmacy generic viagra online pharmacy school

  87. #87

    generic tadalafil no prescription https://cialis.webbfenix.com/

  88. #88

    generic tadalafil no prescription https://cialis.advantagetriseal.com/

  89. #89

    Cialis without a prescription paypal cileve.com generic
    cialis for sale

  90. #90

    I definitely wanted to jot down a quick comment in order to express gratitude to you for the splendid facts you are showing here. My considerable internet search has finally been recognized with professional facts and strategies to talk about with my friends and family. I would express that we readers are unquestionably endowed to exist in a really good website with very many lovely people with helpful solutions. I feel truly blessed to have encountered your website page and look forward to plenty of more thrilling times reading here. Thank you once more for all the details.

    https://www.onfeetnation.com/profiles/blogs/sadsaf21312dsadasd?xg_source=activity

  91. #91

    whoah this blog is magnificent i really like reading your posts. Keep up the great paintings! You already know, lots of persons are hunting round for this information, you can aid them greatly.

    https://www.youtube.com/watch?v=tm_FEaULxf8

  92. #92

    I absolutely love your blog and find a lot of your post’s to be exactly what I’m looking for. Do you offer guest writers to write content for you? I wouldn’t mind publishing a post or elaborating on a lot of the subjects you write concerning here. Again, awesome web log!

    http://www.stornobrzinol.com/

  93. #93

    Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our area library but I think I learned more clear from this post. I’m very glad to see such wonderful info being shared freely out there.

    http://snomoto.com/forums/timbersled/build-new-house-with-us/

  94. #94

    Thank you for sharing excellent informations. Your site is so cool. I am impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched everywhere and just could not come across. What a great web site.

    https://www.peeranswer.com/question/60a83141a303956d751df947

  95. #95

    excellent issues altogether, you simply gained a emblem new reader. What could you suggest in regards to your post that you just made some days in the past? Any sure?

    https://www.onfeetnation.com/profiles/blogs/freerobux

  96. #96

    Some genuinely great articles on this website , regards for contribution.

    https://www.mydigoo.com/forums-topicdetail-277168.html

  97. #97

    You have brought up a very wonderful details , appreciate it for the post.

    https://vc.ru/finance/250101-how-to-use-bitcoin

  98. #98

    My brother recommended I might like this web site. He was totally right. This post actually made my day. You can not imagine just how much time I had spent for this information! Thanks!

    https://m.mydigoo.com/forums-topicdetail-279131.html

  99. #99

    Brooks pharmacy store rx clinic pharmacy charlotte nc wal mart store pharmacy

  100. #100

    Pharmacy clothing store prescription drugs account for 25% of all healthcare-related costs. Rx discount pharmacy hazard ky

  101. #101

    All rx pharmacy canadian pharmacies not requiring prescription
    northwest canadian pharmacy

  102. #102

    Levitra vs cialis side effects generic cialis release date cialis bathtub symbolism

  103. #103

    I went over this internet site and I think you have a lot of excellent information, saved to favorites (:.

    https://www.onfeetnation.com/profiles/blogs/adern341

  104. #104

    Cialis order cheapest cialis online cialis coupon walmart

  105. #105

    Cheap cialis with dapoxetine which works better cialis or viagra cialis eu

  106. #106

    Order cialis online cheap cialis online without free samples
    cialis

  107. #107

    Well I really enjoyed studying it. This tip procured by you is very practical for accurate planning.

    https://digitfi.com

  108. #108

    This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

    https://jupitertv.com

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。