Linux 固定 IP 地址和网关

Linux 固定 IP 地址和网关

查看 IP

ifconfig

ifconfig eth0

ip addr

ip addr show eth0

查看网关

ip route show

route -n

netstat -rn

设置固定 IP

// 配置静态IP文件/etc/network/interfaces
$ vi /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.0.252
gateway 192.168.0.1
netmask 255.255.255.0
#network 192.168.0.0
#broadcast 192.168.0.255

// 重启网卡使配置生效
$ service network restart 

临时设置 IP

$ ifconfig  // 查看所有网卡的配置信息
$ ifconfig eth0  // 查看某网卡的配置信息,如eth0
$ ifconfig eth0 172.16.129.108 netmask 255.255.255.0  // 配置网卡的临时生效的IP地址
$ route add default gw 172.16.129.254  // 配置网关

修改 DNS

sudo vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

保存即可

你可能感兴趣的:(Linux,linux)