ubuntu server18.04配置网络

新安装的服务器,系统安装的ubuntu server18.04, 想当然以为网线插上就能正常连接,谁知不是这么回事。

查阅资料,参考文章

https://www.cnblogs.com/jianxuanbing/archive/2018/11/30/10042892.html

依葫芦画瓢,多次尝试,发现中间vim编辑的小trick,原文未说明。

1. 查看确认网卡信息

(base) xxxxx@jxxx:~$ ifconfig -a
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.105  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::862b:2bff:fe2b:1fde  prefixlen 64  scopeid 0x20<link>
        ether 84:2b:2b:2b:1f:de  txqueuelen 1000  (Ethernet)
        RX packets 4701  bytes 668439 (668.4 KB)
        RX errors 0  dropped 492  overruns 0  frame 0
        TX packets 2200  bytes 325065 (325.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno2: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 84:2b:2b:2b:1f:e0  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno3: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 84:2b:2b:2b:1f:e2  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno4: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 84:2b:2b:2b:1f:e4  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 14804  bytes 1098636 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14804  bytes 1098636 (1.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2. 调用netplan生成文件并编辑配置文件

 sudo netplan generate

sudo vim /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 reboot.  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:
    version: 2
    ethernets:
        eno1:
           addresses:
           - 192.168.0.105/24
           dhcp4: false
           gateway4: 192.168.0.1
           nameservers:
               addresses:
               - 8.8.8.8
        eno1:
           dhcp4: yes

以上将网卡1 设为固定ip, 网卡2设为自动获取

这里注意,缩进全部用空格,不能用tab,否则会报错

3. 运行netplan生效

(base) xxx@jsxxe:~$ sudo netplan apply
(base) xxxx@xxxx:~$ ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.105  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::862b:2bff:fe2b:1fde  prefixlen 64  scopeid 0x20<link>
        ether 84:2b:2b:2b:1f:de  txqueuelen 1000  (Ethernet)
        RX packets 5618  bytes 784304 (784.3 KB)
        RX errors 0  dropped 565  overruns 0  frame 0
        TX packets 2670  bytes 415017 (415.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 14804  bytes 1098636 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14804  bytes 1098636 (1.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

搞定

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海里的鱼2022

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值