今天新做虚拟机,配置了两块网卡。那么ip转发和反向路径校验得注意下。从CentOS7以后,修改/etc/sysctl.conf文件不再有效。看下sysctl.conf文件,里面写着
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
所以我们要修改/usr/lib/sysctl.d/50-default.conf文件,在文件里修改以下内容:
#增加ip_forward = 1以启用ip转发
net.ipv4.ip_forward = 1
# Source route verification
#默认是1,改成0 或2 以取消严格的反向路径校验
#0 表示不开启,1表示开启严格反向路径校验, 2 开启松散的反向路径校验,仅检查源地址是否可达(任意网口)
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
这两项在配置双/多网卡的时候用。