1 安装网络工具,我们需要nmcli这个工具
apt-get install -y network-manager
#shell 自动补全(无效)
#apt-get install -y bash-completion
2 查看网卡信息
root@ubuntu22:/home/libit# 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: 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
# This is the network config written by 'subiquity'
network:
renderer: NetworkManager
network之下全部删除,添加 renderer: NetworkManager
5 应用netplan配置
netplan apply
此时会断网一下,如果使用DHCP的话,可能会获得新IP地址。
6 查看网卡信息
查看网卡信息
root@ubuntu081:/home/libit# nmcli
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地址
#配置主机名ubuntu081
hostnamectl set-hostname ubuntu081
#为网卡ens192设置IP地址
nmcli connection modify ens160 ipv4.addresses 192.168.250.81/20
#设置网关
nmcli connection modify ens160 ipv4.gateway 192.168.240.1
#设置DNS服务器
nmcli connection modify ens160 ipv4.dns 192.168.250.10,202.115.128.33,202.115.128.34
#设置IP方式为手动分配
nmcli connection modify ens160 ipv4.method manual
#禁用IPv6
nmcli connection modify ens160 ipv6.method disabled
#应用新的配置(接下来会断网一下,然后使用新IP地址连接)
nmcli connection up ens160
此时会断网。然后使用新IP地址连接。文章来源:https://www.toymoban.com/news/detail-598204.html
7 添加具有root权限的用户
#添加一个普通用户
adduser testuser
#将其添加到soduers里面
vi /etc/sudoers
添加位置,在root之下,抄root参数文章来源地址https://www.toymoban.com/news/detail-598204.html
# User privilege specification
root ALL=(ALL:ALL) ALL
testuser ALL=(ALL:ALL) ALL
到了这里,关于【】Ubuntu Server 22.04 LTS 设置主机信息以及IP地址的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!