Ubuntu18.04 Server设置静态IP

8 篇文章 0 订阅

前言:Ubuntu18.04 server安装成功之后,有分配到ip,可以上网。但是遇到重启路由,Ubuntu server端ip地址可能会变掉。鉴于在局域网内,一般还是选择固定server端ip。

方案:下面有两种方式。ifconfig or ip a查询当前的网卡enp0s31f6,or ens33 ..

  • Version >=ubuntu18.04,增加透过netplan来设定固定ip的方式,sudo vim /etc/netplan/01-network-manager-all.yaml(文件名可能不同),改完保存,然后sudo netplan apply。
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.1.123/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 114.114.114.114]

 注意yaml语法格式,之后要加空格

  • Version < ubuntu18.04 (or ubuntu18,这里仅示意Ubuntu18之后有改变,不确定具体的版本),通过修改/etc/network/interfaces,并配置dns 【将resolved.conf里的DNS注释拿掉,加入需要的dns】,设定完之后,reboot重启,不要单单的/etc/init.d/networking restart,这样不一定起作用。
  1. sudo vim /etc/network/interfaces
  2. sudo vim /etc/systemd/resolved.conf【修改/etc/resolve.conf不起作用,reboot之后又会被默认值覆盖】
#auto lo
#iface lo inet loopback
auto enp0s31f6
iface enp0s31f6 inet static
address 192.168.1.111  #换成自己的ip address
netmask 255.255.255.0  #换成自己的ip netmask
gateway 192.168.1.1    #换成自己的ip gateway
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
DNS=8.8.8.8 114.114.114.114
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

小结:Ubuntu18.04网络配置有些改变,server已经可以采用netplan配置,也挺方便;注意传统的配置ip/dns的方式,有所改变,/etc/resolvconf/resolv.conf.d/base 已经没有了,需要修改/etc/systemd/resolved.conf。

参考

https://blog.csdn.net/qq_42975842/article/details/81705244

https://blog.csdn.net/qq_36937342/article/details/80876385

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值