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

Kevin 教程 6,552 次浏览 67条评论

安装 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

发表评论

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