以 centos为例
在 /etc/sysconfig/network-scripts/ 目录下存放着配置文件,一般以ifcfg-为前缀,以网卡名为后缀。
查看网卡名
ip a
可以看到网卡名 ens192
编辑ifcfg-ens192 文件
编辑以下内容:
BOOTPROTO=static #静态
IPV6INIT=yes #不需要IPv6地址可以改为no
ONBOOT=yes #开机启动
IPADDR= ip 地址
GATEWAY= #网关地址
NETMASK= #掩码
DNS1= #DNS服务地址
最精简的配置是只保留以下几项
DEVICE=ens192
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.10
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
NDS1=192.168.1.1
然后重启网络服务
systemctl restart networkping 百度
pingbaidu.com
希望能帮到您
喜欢的朋友请点击关注.
linux 设置静态IP地址上网,
有GUI模式的,直接在网卡属性里修改
在CMD模式里,有两种方式,
一种是通过修改配置文件的形式
Ubuntu系统编辑/etc/network/interfaces
auto eth0(开机启用网卡)iface eth0 inet static(设定网卡使用静态IP)address 192.168.0.1(IP地址)netmask 255.255.255.0(子网掩码)gateway 192.168.0.1(网关地址)
保存退出
编辑/etc/resolv.conf
nameserver x.x.x.x(DNS服务器地址)
保存退出
一种是通过命令去修改
ifconfig 网卡名称 inet X.X.X.X netmask 255.255.255.0
route add default gw x.x.x.1
编辑/etc/resolv.conf
nameserver x.x.x.x(DNS服务器地址)
保存退出