【Linux】命令配置网络地址

首先编辑/etc/network/interfaces
设置IP地址和网关,最好先备份,如果你要配置的是eth0网卡,设置如下:

auto eth0 #开机自动连接网络
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static #static表示使用固定ip,dhcp表述使用动态ip
address 198.9.146.131 #设置ip地址
netmask 255.255.255.0 #设置子网掩码
gateway 198.9.146.254 #设置网关

BTW:配置时可去掉注释,因为我配置的时候加了注释导致网卡起不来;如果远程一定要auto,不然配置后网卡不自动启。

其次编辑/etc/resolv.conf配置dns,设置如下:

nameserver 198.9.9.1 #设置首选dns
nameserver 198.9.9.2 #设置备用dns

最后重启网络

service networking restart #重启网络

查看IP:

ifconfig eth0

 

以上是编辑文件,可能会出错,下面使用命令

 

#设置IP:
ifconfig eth1 10.3.1.74

#把IP: 129.158.215.204 , netmask: 255.255.255.0分配给eth0,
# ifconfig eth0 129.158.215.204 netmask 255.255.255.0

#自动获取IP;
ifconfig eth1 dhcp start (从eth1走,不需要ip即可dhcp)

 

posted on 2018-12-17 14:25  Beatfan  阅读(36)  评论(0)    收藏  举报

导航