这里我采用修改网络配置文件的方式配置网卡的ip地址,网络服务重启ip地址也不会丢失
1.进入到网络配置文件目录/etc/sysconfig/network-scripts,这里可以看到以ifcfg-开头的文件
2.打开配置文件为网卡enp0s3配置一些ip相关信息,保存文件退出
相关配置说明如下:
TYPE=Ethernet ##网卡类型为以太网
NAME=enp0s3 ##指定网络链接的名字为eth0,个人习惯,开心就好
DEVICE=enp0s3 ##指定文件管理的网卡名称
BOOTPROTO=static ##ip是否动态获取:dhcp动态获取,none和static表示静态网络
ONBOOT=yes ##是否开机启动
IPADDR=192.168.1.110 ##设定ip为192.168.1.110
NETMASK=255.255.255.0 ##子网掩码
GATEWAY=192.168.1.1 ##网关地址
DNS1=114.114.114.114 ##DNS地址,如需域名解析需要设置
DNS2=8.8.8.8
3.重启网络服务,或者重启单个网卡
#重启网络服务,下面的两个语句都可以
[root@localhost ~]#service network restart
[root@localhost ~]#systemctl restart network
#重启单个网卡
[root@localhost ~]#ifdown enp0s3
[root@localhost ~]#ifup enp0s3
4.最后查看网卡ip地址
[root@localhost ~]# ip addr show enp0s3
到此网卡的ip配置完成了,有时我们想要临时配ip地址,可以使用ifconfig命令进行设置
ifconfig enp0s3 192.168.1.110 netmask 255.255.255.0
------------------------------------------------------------------------------------------------------------------------------------------------------------
其他相关
查看DNS配置
[root@localhost /]# cat /etc/resolv.conf
centos关闭防火墙的方法:
#查看防火墙状态: systemctl status firewalld.service #关闭防火墙: systemctl stop firewalld #启动防火墙: systemctl start firewalld #开机自动关闭: systemctl disable firewalld #开启自动启动: systemctl enable firewalld #查看开启是否启动: chkconfig --list|grep network |