1 安装网络工具,我们需要nmcli这个工具
apt-get install -y network-manager
2 查看网卡信息
root@ubuntu22:/home/libit 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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc: mq state UP group default qlen 1000 link/ether 00:50:56:b6:68:a3 brd ff:ff:ff:ff:ff:ff altname enp3s0 inet 192.168.240.144/20 metric 100 brd 192.168.255.255 scope global dynamic ens160 valid_lft 473sec preferred_lft 473sec inet6 fe80::250:56ff:feb6:68a3/64 scope link valid_lft forever preferred_lft forever
得知网卡为 ens160
3 启用network-manager
编辑配置文件
vim /etc/NetworkManager/NetworkManager.conf
[main] plugins=ifupdown,keyfile [ifupdown] managed=true [device] wifi.scan-rand-mac-address=no
设置 managed=true
4 编辑/etc/netplan/*.yaml
vim /etc/netplan/00-installer-config.yaml
network: renderer: NetworkManager
network之下全部删除,添加 renderer: NetworkManager
5 应用netplan配置
netplan apply
此时会断网一下,如果使用DHCP的话,可能会获得新IP地址。
6 查看网卡信息
查看网卡信息
root@ubuntu081:/home/libit ens160: connected to Wired connection 1 "VMware VMXNET3" ethernet (vmxnet3), 00:50:56:B6:51:AD, hw, mtu 1500 ip4 default inet4 192.168.240.69/20 route4 192.168.240.0/20 metric 100 route4 default via 192.168.240.1 metric 100 inet6 fe80::250:56ff:feb6:51ad/64 route6 fe80::/64 metric 256 lo: unmanaged "lo" loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 DNS configuration: servers: 202.115.128.33 202.115.128.34 61.139.2.69 domains: mlib.cdut.cn interface: ens160 Use "nmcli device show" to get complete information about known devices and "nmcli connection show" to get an overview on active connection profiles. Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
得知:ens160 连接到 Wired connection 1
修改网卡id
nmcli connection modify "Wired connection 1" connection.id ens160
6 配置主机信息
配置主机名,设置IP地址
hostnamectl set-hostname ubuntu081 nmcli connection modify ens160 ipv4.addresses 192.168.250.81/20 nmcli connection modify ens160 ipv4.gateway 192.168.240.1 nmcli connection modify ens160 ipv4.dns 192.168.250.10,202.115.128.33,202.115.128.34 nmcli connection modify ens160 ipv4.method manual nmcli connection modify ens160 ipv6.method disabled nmcli connection up ens160
此时会断网。然后使用新IP地址连接。
7 添加具有root权限的用户
adduser testuser vi /etc/sudoers
添加位置,在root之下,抄root参数
root ALL=(ALL:ALL) ALL testuser ALL=(ALL:ALL) ALL
原文链接:https://blog.csdn.net/u013667796/article/details/125644825
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END