1)给服务器设置静态IP 接口名称为eth0
1.设置新主机名(重启后永久生效)
[root@localhost ~]# hostnamectl set-hostname lee.sample.com
2.查看网卡设备
[root@lee ~]# nmcli device
设备 类型 状态 CONNECTION
virbr0 bridge 连接的 virbr0
eth0 ethernet 连接的 System eth0
virbr0-nic tap 连接的 virbr0-nic
lo loopback 未管理 --
3.设置IP地址(引号括起来的是网卡名,通过nmcli device得知)
[root@lee ~]# nmcli connection modify "System eth0" ipv4.addresses 10.0.0.30/24
4.设置网关(引号括起来的是网卡名,通过nmcli device得知)
[root@lee ~]# nmcli connection modify "System eth0" ipv4.gateway 10.0.0.1
5.设置Dns(引号括起来的是网卡名,通过nmcli device得知)
[root@lee ~]# nmcli connection modify "System eth0" ipv4.dns 10.0.0.1
6.关闭DHCP
[root@lee ~]# nmcli connection modify "System eth0" ipv4.method manual
7.重启网卡
[root@lee ~]# nmcli connection down "System eth0" ; nmcli connection up "System eth0"
8.查看网卡详细信息
[root@lee ~]# nmcli device show eth0
GENERAL.设备: eth0
GENERAL.类型: ethernet
GENERAL.硬盘: 00:1C:42:05:FB:35
GENERAL.MTU: 1500
GENERAL.状态: 100 (连接的)
GENERAL.CONNECTION: System eth0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/3
WIRED-PROPERTIES.容器: 开
IP4.地址[1]: 172.25.0.1/24
IP4.网关:
IP6.地址[1]: fdb2:2c26:f4e4:1:21c:42ff:fe05:fb35/64
IP6.地址[2]: fe80::21c:42ff:fe05:fb35/64
IP6.网关:
IP6.路由器[1]: dst = fdb2:2c26:f4e4:1::/64, nh = ::, mt = 100
9.查看状态
[root@lee ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:1c:42:05:fb:35 brd ff:ff:ff:ff:ff:ff
inet 172.25.0.1/24 brd 172.25.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fdb2:2c26:f4e4:1:21c:42ff:fe05:fb35/64 scope global dynamic
valid_lft 2591504sec preferred_lft 604304sec
inet6 fe80::21c:42ff:fe05:fb35/64 scope link
valid_lft forever preferred_lft forever
2)如果不需要,关闭IPv6启动
[root@lee ~]# vim /etc/default/grub //修改启动配置文件
GRUB_CMDLINE_LINUX="ipv6.disabled=1 crashkernel=auto rd.lvm.lv=VolGroup/lv_root rd.lvm.lv=VolGroup/lv_swap rhgb quiet" //添加一行ipv6.disabled=1
[root@lee ~]# grub2-mkconfig -o /boot/grub2/grub.cfg //重读配置文件