linux网络配置

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.29
sudo 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.114

DNS2=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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值