Linux网络命令 ip

1、基础

查看网络IP

ip addr

host文件位置:/etc/hosts

vi /etc/hosts

配置地址

vi /etc/sysconfig/network-scripts/ifcfg-enxxx

# 默认自启动需要修改配置:
ONBOOT=yes

重启网卡

systemctl restart network

查看本地DNS

more /etc/resolv.conf

 

网络问题

1、双网卡同时只有一个IP生效

Linux默认开启了反向路由检查,如果2个网卡在一个Lan里面,那么服务器可能从eth0或者eth1发现网关, 如果一个包从eth0进入了, 而网关在eth1上, 那么从eth1是出不去的, 就不通了。导致在2个网卡只有一个网关生效,关闭反向路由检查即可。

临时方案

echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter 
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter 
echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter

永久方案

vi /etc/sysctl.conf

net.ipv4.conf.em3.rp_filter = 0
net.ipv4.conf.em4.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

# 生效
sysctl -p