CentOS modify a fixed IP address
Reference Address: https://www.cnblogs.com/technology-huangyan/p/9146699.html
https://blog.csdn.net/rossisy/article/details/77855798
https://www.cnblogs.com/technology -huangyan / p / 9146699.html
First check the local IP address of the first
ip addr
If you are in VMWare EXSI web version, if not all content is displayed, you need to increase | more
ip addr | more
1. As the network ens192 is our current network, need to be modified to a fixed IP address, that ens192
vi /etc/sysconfig/network-scripts/ifcfg-ens192
The default content below
Which ONBOOT = "yes", indicating that it is to start the card
The need to increase the settings
IPADDR #IP address
PREFIX # prefix? ?
NETMASK # subnet mask
NETWORK #IP segment
GATEWAY # gateway address
# This program is based on DNS settings set in the main card,
# resolv.conf DNS automatically generated in accordance with the contents of the card set
# later want to change the DNS, you must modify the network card settings in DNS settings will not have problems after the failure of the server restarts
DNS1 # default DNS address, the card program to the DNS-based,
PEERDNS #
另外,特别注意,其中BOOTPROTO="static"选项即是固定IP地址
请仔细参考:https://blog.csdn.net/w670328683/article/details/61923858
2.编辑/etc/sysconfig/network
#网上推荐更改 NETWORKING=yes HOSTNAME=localhost.localdomain GATEWAY=192.168.191.2 #网关地址
vi /etc/sysconfig/network #尝试本机更改
172.17.130.131并未更改该项,暂时还未影响正常服务
3. 编辑/etc/resolv.conf,如果按上面的配置,这个应该会自动生成的
#网上的推荐更改为这两个 nameserver 8.8.8.8 nameserver 114.114.114.114
vi /etc/resolv.conf #尝试本机更改
4.重启网络服务
systemctl restart network.service #重启网络服务
systemctl status network.service #查看网络服务状态
出现问题
在重启了网络服务后,发现服务器IP地址是更改为配置了,但docker启动的容器却不可以正常访问(使用浏览器访问docker服务)
尝试解决
第一步:尝试重启docker服务
sudo systemctl daemon-reload sudo systemctl restart docker
最后发现,docker重启后,服务已经可以正常访问
第二步,安装一个工具net-tools
yum install net-tools
如果在更改了IP地址后,出现无法ping baidu.com,或者无法安装应用的情况,那么一般来说是DNS解析出了问题,回到修改/etc/resolv.conf,看看其中是不是有nameserver 8.8.8.8的配置在其中,如果有,应该就不是解析的问题了
通过命令查看服务器端口占用情况
netstat -lntp
可以查看到有哪些端口被占用了,这里可以看到,占用端口的应用都是docker-proxy