Ubuntu23.04静态ip地址设置

Ubuntu23.04的静态ip的管理方式较之前的系统版本有很大的改变

1、管理文件

/etc/netplan/00-installer-config.yaml

2、操作之前先看默认网卡名字(我这里是ens3)

root@wanyan:/etc/zabbix# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:5c:5d:63 brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    inet 192.168.20.36/24 metric 100 brd 192.168.20.255 scope global dynamic ens3
       valid_lft 22137sec preferred_lft 22137sec
    inet6 fe80::5054:ff:fe5c:5d63/64 scope link
       valid_lft forever preferred_lft forever

3、管理文件配置格式

###设置固定ip的格式
network:
    ethernets:
        [network-interface-name]:
            dhcp4: no
            addresses: [ip-address/subnet-mask]
            gateway4: [default-gateway]
            nameservers:
                addresses: [dns-server]
    version: 2
###默认的dhcp的格式
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens3:
      dhcp4: true
  version: 2

4、设置固定ip地址

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens3:
      dhcp4: no
      addresses: [192.168.20.36/24]
      gateway4: 192.168.20.254
      nameservers:
        addresses: [223.5.5.5,223.6.6.6]
  version: 2

5、应用命令

root@wanyan:/etc/zabbix# netplan apply

** (generate:15677): WARNING **: 13:25:11.214: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.

** (generate:15677): WARNING **: 13:25:11.214: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
Cannot call openvswitch: ovsdb-server.service is not running.

** (process:15675): WARNING **: 13:25:11.516: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:15675): WARNING **: 13:25:11.516: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:15675): WARNING **: 13:25:11.572: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:15675): WARNING **: 13:25:11.572: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:15675): WARNING **: 13:25:11.572: Permissions for /etc/netplan/00-installer-config.yaml are too open. Netplan configuration should NOT be accessible by others.

** (process:15675): WARNING **: 13:25:11.572: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

根据上边的提示做如下修改(网卡的名字需要根据实际情况调整,比如的主机是ens3)

root@wanyan:/etc/zabbix# chmod  600 /etc/netplan/00-installer-config.yaml
root@wanyan:/etc/zabbix#apt install openvswitch-switch -y
root@wanyan:/etc/zabbix#systemctl start ovsdb-server
root@wanyan:/etc/zabbix#systemctl enable ovsdb-server

root@wanyan:~# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens3:
      dhcp4: false
      addresses: [192.168.20.36/24]
      optional: true
      routes:
        - to: default
          via: 192.168.20.254
      nameservers:
        addresses: [223.5.5.5,223.6.6.6]
  version: 2

root@wanyan:~# netplan apply
root@wanyan:~# ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.20.36  netmask 255.255.255.0  broadcast 192.168.20.255
        inet6 fe80::5054:ff:fe5c:5d63  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:5c:5d:63  txqueuelen 1000  (Ethernet)
        RX packets 56671  bytes 84570573 (84.5 MB)
        RX errors 0  dropped 3995  overruns 0  frame 0
        TX packets 36475  bytes 3779428 (3.7 MB)
        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 610  bytes 44650 (44.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 610  bytes 44650 (44.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

完颜振江

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

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

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

打赏作者

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

抵扣说明:

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

余额充值