目录
网络管理
(1)查看IP信息:
route -n
ip addr
(2)配置临时生效的网络连接
ip -4 addr add 172.25.254.2/24 dev ens224
(3)修改配置文件配置网络连接(network服务)
[root@server ~]# cd /etc/NetworkManager/system-connections/ #网卡配置文件所在目录
[root@server ~]# chmod 600 ens160.connection
[root@server ~]# nmcli connection reload
[root@server ~]# nmcli connection up ens160
/etc/resolv.conf
/etc/resolv.conf 它是DNS客户机配置文件,用于设置DNS服务器的IP地址及DNS域名,还包含了主机的域名搜索顺序。
/etc/resolv.conf 配置文件认识_resolve.conf-CSDN博客
(4)shell脚本批量IP设置
该脚本放置在/usr/local/bin/vmset.sh【可直接执行】
[root@local ~]# vim /bin/vmset.sh
[root@local ~]# cat /bin/vmset.sh
#!/bin/bash
rm -fr /etc/NetworkManager/system-connections/$1.nmconnection
cat > /etc/NetworkManager/system-connections/$1.nmconnection <<EOF
[connection]
id=$1
type=ethernet
interface-name=$1
[ipv4]
address1=$2/24,172.25.254.2
method=manual
dns=114.114.114.114;
EOF
chmod 600 /etc/NetworkManager/system-connections/$1.nmconnection
nmcli connection reload
nmcli connection up $1
hostnamectl hostname $3
cat > /etc/hosts <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
$2 $3
EOF
[root@local ~]# chmod +x /usr/local/bin/vmset.sh
tips:
[root@server ~]# grubby --update-kernel ALL --args net.ifnames=0
内核中禁止使用net.ifnames模块,这样可以让网卡显示为ethx