编写/etc/sysconfig/network-scripts/
下的ifcfg-打头的文件,具体不同系统显示的不一样。
把ONBOOT=no改成ONBOOT=yes
然后重启网络服务
执行 service network restart
命令
使用ifconfig
命令查看分配的ip地址。
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.254.129 netmask 255.255.255.0 broadcast 192.168.254.255
inet6 fe80::85d7:2bd7:31be:24d1 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:fa:b4:89 txqueuelen 1000 (Ethernet)
RX packets 1041 bytes 67354 (65.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 95 bytes 11255 (10.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 512 bytes 44544 (43.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 512 bytes 44544 (43.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
上面这种是自动分配,因为默认BOOTPROTO=dhcp,从上面可以知道自动分配到了192.168.254.129的ip.
自定义IP的设置
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
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=ens33
UUID=7c523d95-f232-4f37-9752-35e0229d6afa
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.254.102
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@localhost ~]#
修改的地方
1、把之前的BOOTPROTO=dhcp改成BOOTPROTO=none
2、把ONBOOT=no改成ONBOOT=yes
3、加上自定义ip,子网掩码,网关配置。
重启网卡服务
使用ifconfig命令验证
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.254.102 netmask 255.255.255.0 broadcast 192.168.254.255
inet6 fe80::8ed:2773:e45f:4e50 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d1:e4:86 txqueuelen 1000 (Ethernet)
RX packets 263 bytes 20437 (19.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 99 bytes 12911 (12.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 464 bytes 40384 (39.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 464 bytes 40384 (39.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#