Linux下网络配置常用命令

临时修改IP生效

ifconfig eth0 192.168.0.3 netmask 255.255.255.0

临时增加IP

ifconfig eth0:1 192.168.0.3 netmask 255.255.255.0

⚠️临时修改和增加IP,重启机器后失效,如果想重启之后依然生效,可以修改网卡配置文件。

网卡配置文件修改方法:
centos: 修改 /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 #网卡对应的设备别名
BOOTPROTO=static #网卡获得ip地址的方式(默认为dhcp,表示自动获取)
HWADDR=00:07:E9:05:E8:B4 #网卡MAC地址(物理地址)
IPADDR=192.168.100.100 #IP地址
NETMASK=255.255.255.0 #子网掩码
ONBOOT=yes #系统启动时是否激活此设备

ubuntu: 修改 /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0

重启网卡

centos: sudo service network restart
ubuntu: sudo /etc/init.d/networking restart

扫描二维码关注公众号,回复: 11240814 查看本文章

猜你喜欢

转载自blog.csdn.net/BUG_88/article/details/105816080