分享

IP Forwarding打开

 pandazh 2014-02-14

英文源URL:http://www./2006/08/01/how-to-enable-ip-forwarding-in-linux/

   一般情况下,我们的linux机器的ip forwarding选项都是关闭的。 但是如果我们的机器需要做网关,或路由器。那么这个就要打开了。

首先检查下ip forwarding是否已经打开。

  1. //  Using sysctl:  
  2. sysctl net.ipv4.ip_forward  
  3. net.ipv4.ip_forward = 0  
  4.   
  5. //或者 just checking out the value in the /proc system  
  6. cat /proc/sys/net/ipv4/ip_forward  
  7. 0  
  8. //打开ip forwarding  
  9. sysctl -w net.ipv4.ip_forward=1  
  10. //同样的或者  
  11. echo 1 > /proc/sys/net/ipv4/ip_forward  
  12.   
  13. //这样的设置只是一次性的。我们可以永久的设置成打开。如下:  
  14. //将文件设置/etc/sysctl.conf:  
  15. net.ipv4.ip_forward = 1  
  16. //如果已经将ip forwarding由0设置为1。为了使它生效。我们执行如下的命令。  
  17. sysctl -p /etc/sysctl.conf  
  18.   
  19. //RedHat中执行如下:  
  20. service network restart  
  21.   
  22. //Ubuntu/Debian系统则重启procps服务  
  23. /etc/init.d/procps.sh restart  

  1. /*  
  2. 下面这段看看linux中的rp_filter是干什么的  
  3.   
  4.  rp_filter, which automatically rejects incoming packets if the  
  5.   
  6.  routing table entry for their source address doesn't match the  
  7.   
  8.  network interface they're arriving on. This has security  
  9.   
  10.  advantages because it prevents the so-called IP spoofing,  
  11.   
  12.  however it can pose problems if you use asymmetric routing  
  13.   
  14.  (packets from you to a host take a different path than packets  
  15.   
  16.  from that host to you) or if you operate a non-routing host  
  17.   
  18.  which has several IP addresses on different interfaces.   
  19. */  
  20.   
  21. To turn rp_filter off, uncomment the lines below:  
  22.   
  23. /etc/sysctl.conf  
  24.   
  25. #net.ipv4.conf.default.rp_filter=1  
  26.   
  27. #net.ipv4.conf.all.rp_filter=1  
  28.   
  29.   
  30. /etc/sysctl.d/10-network-security.conf  
  31.   
  32. #net.ipv4.conf.default.rp_filter=1  
  33.   
  34. #net.ipv4.conf.all.rp_filter=1  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多