ubuntu 网络管理
1 查看ip地址
root@u22-tools-20:~# ip addr
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:32:93:36 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.254.20/24 brd 192.168.254.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe32:9336/64 scope link
valid_lft forever preferred_lft forever
备注:
ens33 网络接口
inet 192.168.254.20/24 ip地址
2 查看路由
root@u22-tools-20:~# ip route
default via 192.168.254.2 dev ens33 proto static
192.168.254.0/24 dev ens33 proto kernel scope link src 192.168.254.20
3 设置静态ip地址
root@u22-tools-20:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
addresses:
- 192.168.254.20/24
nameservers:
addresses:
- 192.168.254.2
search: []
routes:
- to: default
via: 192.168.254.2
version: 2
#让修改网络配置生效
root@u22-tools-20:~# netplan apply
WARNING:root:Cannot call Open vSwitch: ovsdb-server.service is not running.
备注:
ens33:
addresses: ip地址
nameservers:
addresses: 网关
routes:
- to: default DNS