CentOs 设置静态IP
1.修改网卡配置 编辑:vi /etc/sysconfig/network-scripts/ifcfg-eno49
通过ifconfig命令,查看在用的网卡(特别是网卡别名)。也可以进入/etc/sysconfig/network-scripts目录,然后ls -a列出当前目录清单,找到对应的网卡配置文件
[root@localhost ~]# ifconfig eno49: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.25.127 netmask 255.255.255.0 broadcast 192.168.25.255 inet6 fe80::5aaf:8e77:99c5:b91b prefixlen 64 scopeid 0x20<link> ether XX:XX:XX:XX:XX:XX txqueuelen 1000 (Ethernet) RX packets 21072 bytes 2744576 (2.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 28835 bytes 30976082 (29.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 16
在打开的文件中,修改IPADDR、GATEWAY和DNS1等配置项。
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="none" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="eno49" UUID="b6a8a293-XXXX-XXXX-XXXX-1e4db2096a9e" DEVICE="eno49" ONBOOT="yes" IPADDR="192.168.25.127" PREFIX="24" GATEWAY="192.168.25.254" DNS1="XXX.XXX.XXX.XXX" IPV6_PRIVACY="no"
2.修改网关配置 编辑:vi /etc/sysconfig/network
[root@localhost ~]# cd /etc/sysconfig [root@localhost sysconfig]# ls -a . cbq crond init kdump netconsole rdisc run-parts sysstat.ioconf .. chronyd ebtables-config ip6tables-config kernel network readonly-root selinux wpa_supplicant anaconda console firewalld iptables-config man-db network-scripts rsyncd sshd authconfig cpupower grub irqbalance modules ntpdate rsyslog sysstat
3.修改DNS 配置 编辑:vi /etc/resolv.conf
4.重启网络服务 执行命令:service network restart 或 /etc/init.d/network restart