1

让服务器响应整个网段中的请求

 2 years ago
source link: https://blogread.cn/it/article/8344?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
您现在的位置首页 --> 网络系统 --> 让服务器响应整个网段中的请求

让服务器响应整个网段中的请求

浏览:152次  出处信息

最近有个需求是让某个服务器能够响应一整个网段的请求,研究了一下,发现比想象的容易。

假设需要的网段是 172.16.0.0/16 (好多IP!) 我们需要让用户能用这个段里面任何一个 IP 访问我的服务器,服务器IP实际是 192.168.1.4 ,那么分这样两步走就行。

1: 在路由上将 172.16.0.0/16 设置一条静态路由,网关是 192.168.1.4
在别的机器上 ping 172.16 段里面任何一个 IP,肯定现在还 ping 不通,但是在 192.168.1.4 上抓包,保证报文已经被路由到了这台服务器
2: 给本机的 lo 上增加一条 local 表里面的路由
ip route add local 172.16.0.0/16 dev lo

然后就一切正常了。

PS: 这个办法 IPV6 一样可以用,例如
ip route add local fc::/64 dev lo
就可以让 Linux 响应 fc::/64 里面所有的 IP

PS1: 除了路由器上设置服务器为网关,其实还有其他办法让请求报文能到达服务器,V4 可以用 tarpd,V6 可以用 ndppd,但是这些方法都会给网关和服务器的 ARP 表和邻居表里面增加非常多的记录,对性能有很大影响,因此不建议使用,还是用静态路由的方式比较好。

PS2: 不要设置在 eth0 上,可能会造成一些其他问题,lo 就挺好的

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK