首先查看网口地址ifconfig
[root@shijie ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fe53:ce07 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:53:ce:07 txqueuelen 1000 (Ethernet)
RX packets 489 bytes 48089 (46.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 191 bytes 34403 (33.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
方法1.编辑配置文件
网口配置文件目录:/etc/sysconfig/network-script/ifcfg-eno16777736
vim /etc/sysconfig/network-script/ifcfg-eno16777736
TYPE=Ethernet # 设备类型
BOOTPROTO=static # 地址分配模式
NAME=eno16777736 # 网卡名称
**ONBOOT=yes # 是否启动 重要:开机后是否自启**
IPADDR0=192.168.10.10 # IP地址
NETMASK=255.255.255.0 # 子网掩码 或者 PREFIX0=24
GATEWAY=192.168.10.1 # 网关地址
DNS1=192.168.10.1 # DNS地址
方法2.ifconfig ethx x.x.x.x netmask x.x.x.x
实时生效,不需要重启网络服务,重启后失效。
ifconfig eno16777736 192.168.10.10 netmask 255.255.255.0
方法3.nmtui网卡编辑工具
方法4:图形界面中设置网络
网卡模板功能
在不同场景下使用不同的网络设置进行快速切换
添加company和house两个网络配置模板
[root@shijie ~]# nmcli connection add con-name company ifname eno16777736 autoconnect no type ethernet ip4 192.168.10.10/24 gw4 192.168.10.1
Connection 'company' (86c71220-0057-419e-b615-38f4014cfdee) successfully added.
[root@shijie ~]# nmcli connection add con-name house type ethernet ifname eno16777736
Connection 'house' (44acf0a7-07e2-40b4-94ba-69ea973090fb) successfully added.
查看网路会话模板
[root@shijie ~]# nmcli connection show
名称 UUID 类型 设备
house df19ad40-e2fb-4ffb-b0f8-14aa60cf86e1 802-3-ethernet --
company 67746b28-e089-4603-b3e2-3d41152d5b31 802-3-ethernet --
eno16777736 d6dca6f7-2aca-4c7d-8c36-c6cb19059141 802-3-ethernet eno16777736
启用house网络地址切换,实时生效不需要重启网络服务
nmcli connection up house
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
重启网络服务
systemctl restart network