ubuntu
低版本
sudo vi /etc/network/interfaces
.根据自己的需求修改设置address、gateway、netmask这三个值即可
auto eth0
iface eth0 inet static
address 192.168.1.110 #ip地址
gateway 192.168.1.1 #网关
netmask 255.255.255.0 #子网掩码sudo /etc/init.d/networking restart
高版本
sudo vim /etc/netplan/00-installer-config.yaml network: ethernets: ens32: addresses: - 192.168.xx.xx/24 ## 此处改为自己的IP gateway4: 192.168.xx.1 ## 网关 nameservers: addresses: - 119.29.29.29sudo netplan apply ## 没有报错,说明配置没有问题
centos
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0
BOOTPROTO=static #设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的 ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址
ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备
IPADDR=12.168.1.2 #如果设置网卡获得 ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址
NETMASK=255.255.255.0 #网卡对应的网络掩码GATEWAY=192.168.1.254 #对应的子网广播地址
DNS1=114.114.114.114DNS2=8.8.8.8
HWADDR=00:07:E9:05:E8:B4 #对应的网卡物理地址
# 关闭防火墙 systemctl stop firewalld.service
# 查看防火墙的状态 firewall-cmd --state
# 禁止firewall开机启动 systemctl disable firewalld.service
# 开放name server默认端口
firewall-cmd --remove-port=9876/tcp --permanent
# 开放master默认端口
firewall-cmd --remove-port=10911/tcp --permanent
# 开放slave默认端口 (当前集群模式可不开启)
firewall-cmd --remove-port=11011/tcp --permanent
# 重启防火墙
firewall-cmd --reload