# 禁用IPv6 echo"net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf # 查看网卡 nmcli c show # ens34是查看的网卡名称 # 固定本机IP nmcli c m "ens34" IPv4.address 10.0.1.7/24; nmcli c m "ens34" IPv4.gateway 10.0.0.1; # 固定dns nmcli c m "ens34" IPv4.dns "10.0.1.20 223.5.5.5"; nmcli c m "ens34" IPv4.method manual; nmcli c m "ens34" connection.autoconnect yes nmcli c reload nmcli c up ens34
1.2.network-scripts方式(rhel7及以前)
如果是 centos7 及以前,如果你没有挂载你的以太网卡,参见如下流程:
1 2
cd /etc/sysconfig/network-scripts/ ls -all
我的设备上,是如下名称:
1 2 3 4
total 8 drwxr-xr-x. 2 root root 26 Jan 4 02:15 . drwxr-xr-x. 7 root root 4096 Mar 7 16:32 .. -rw-r--r--. 1 root root 312 Mar 7 16:08 ifcfg-enp4s0
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors Disk model: Virtual disk Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 17275980-77A0-40AD-8699-6033181819C3
Device Start End Sectors Size Type /dev/sda1 2048 1230847 1228800 600M EFI System /dev/sda2 1230848 3327999 2097152 1G Linux filesystem /dev/sda3 3328000 83884031 80556032 38.4G Linux LVM
Command (m forhelp): d Partition number (1-3, default 3): 3
Partition 3 has been deleted.
Command (m forhelp): n Partition number (3-128, default 3): First sector (3328000-629145566, default 3328000): Last sector, +/-sectors or +/-size{K,M,G,T,P} (3328000-629145566, default 629145566):
Created a new partition 3 of type'Linux filesystem' and of size 298.4 GiB. Partition #3 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: N Command (m forhelp): w