歡迎您光臨本站 註冊首頁

用Iptables+RedHatLinux9.0做ADSL路由器

←手機掃碼閱讀     火星人 @ 2014-03-29 , reply:0

  說明和約定
  
  #所有在"[ ]" 中的都是應該直接在命令行敲入的命令
  
  1.前言
  最近在幫一個朋友做他們公司的ADSL網關路由, 原來是用FreeBSD做的,現在給他重新用Red Hat Linux 做.
  
  2.安裝準備和環境說明
  1) Red Hat Linux 9.0 最小化安裝, 直接選擇安裝類型中的Custom,然後在包安裝時選擇最下面的選項 "最小化安裝", 此模式用於做路由網關已經完全足夠
  
  3.軟體調整
  1)rp-pppoe
  直接執行它的配置命令即可:
  [ adsl-start ]
  Welcome to the Roaring Penguin ADSL client setup. First, I will run
  
  some checks on your system to make sure the PPPoE client is installed
  
  properly...
  
  Looks good! Now, please enter some information:
  
  USER NAME
  
  >>> Enter your PPPoE user name : [enter ADSL-Login-UserName here]
  
  INTERFACE
  
  >>> Enter the Ethernet interface connected to the ADSL modem
  
  For Solaris, this is likely to be something like /dev/hme0.
  
  For Linux, it will be ethn, where n is a number.
  
  (default eth1): [Enter your right interface here. normaly should be eth0 or eth1]
  
  >>> Enter the demand value (default no): [預設值就可以了, 直接回車]
  
  DNS
  
  >>> Enter the DNS information here: [server] # server 表示DNS 由ISP 指定
  
  PASSWORD
  
  >>> Please enter your PPPoE password: [] # ADSL撥號的密碼
  
  >>> Please re-enter your PPPoE password:
  
  FIREWALLING
  
  The firewall choices are:
  
  0 - NONE: This script will not set any firewall rules. You are responsible
  
  for ensuring the security of your machine. You are STRONGLY
  
  recommended to use some kind of firewall rules.
  
  1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
  
  2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway for a LAN
  
  >>> Choose a type of firewall (0-2): [2] #還是要防火牆比較好
  ** Summary of what you entered **
  
  Ethernet Interface: eth1
  
  User name: ddtthz!Internet
  
  Activate-on-demand: No
  
  DNS: server
  
  Firewalling: NONE
  
  >>> Accept these settings and adjust configuration files (y/n)? [y] # 完成!
  
  2) 網路環境描述
  (1) /etc/sysctl.conf
  net.ipv4.ip_forward = 1
  
  (2) eth0 接ADSL 線, eth1 (192.168.1.4/24) 連接內部LAN(192.168.1.0/24)
  
  3)iptables
  對於熟悉Ipchains的管理員應該注意的事項:
  iptables與ipchains的區別
  
  ·iptables的預設鏈的名稱從小寫換成大寫,並且意義不再相同:INPUT和OUTPUT分別放置對目的地址是本機以及本機發出的數據包的過慮規則。
  ·-i選項現在只代表輸入網路介面,輸入網路介面則使用-o選項。
  ·TCP和UDP埠現在需要用--source-port或--sport(或--destination-port/--dport)選項拼寫出來並且必須置於"-p tcp"或"-p udp"選項之後,因為它們分別是載入TCP和UDP擴展的。
  ·以前TCP的"-y"標誌現在改為"--syn",並且必須置於"-p tcp"之後。
  ·原來的DENY目標最後改為了DROP。
  ·可以在列表顯示單個鏈的同時將其清空。
  ·可以在清空內建鏈的同時將策略計數器清零。
  ·列表顯示鏈時可顯示計數器的當前瞬時值。
  ·REJECT和LOG現在變成了擴展目標,即意味著它們成為獨立的內核模塊。
  ·鏈名可以長達31個字元。
  ·MASQ現在改為MASQUERADE,並且使用不同的語法。REDIRECT保留原名稱,但也改變了所使用的語法。
  設計思路:
  (1) 首先禁止轉發任何包,然後再一步步設置允許通過的包。
  [ /sbin/iptables -P FORWARD DROP ]
  
  (2) MASQUERADE the PPP link
  [ /sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE ]
  
  (3) 允許兩台特定的機器可以訪問外部WWW,以MAC地址為依據
  
  [/sbin/iptables -A FORWARD -m mac --mac-source 00-11-d4-f0-39-53 -p tcp --dport 80 -j ACCEPT
  ]
  
  [/sbin/iptables -A FORWARD -m mac --mac-source 00-e1-4f-32-39-3f -p tcp --dport 80 -j ACCEPT]
  
  [/sbin/iptables -A FORWARD -m mac --mac-source 00-11-d4-f0-39-53 -p tcp --dport 443 -j ACCEPT
  ]
  
  [/sbin/iptables -A FORWARD -m mac --mac-source 00-e1-4f-32-39-3f -p tcp --dport 443 -j ACCEPT]
  
  (4) 允許SMTP 和POP3 以及IMAP
  
  [/sbin/iptables -A FORWARD -p tcp -s 192.168.1.0/24 --dport 25 -i eth1 -j ACCEPT]
  
  [/sbin/iptables -A FORWARD -p tcp -s 192.168.1.0/24 --dport 110 -i eth1 -j ACCEPT]
  
  [/sbin/iptables -A FORWARD -p tcp -s 192.168.1.0/24 --dport 143 -i eth1 -j ACCEPT]
  
  (5)拒絕其它機器訪問internet www
  
  [ /sbin/iptables -A FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j REJECT]
  
  
  [/sbin/iptables -A FORWARD -s 192.168.1.0/24 -p tcp --dport 443 -j REJECT]
  
  (6)禁止 MSN
  
  [/sbin/iptables -A FORWARD -p TCP --dport 1863 -j REJECT ]
  
  [/sbin/iptables -A FORWARD -d 64.4.13.0/24 -j REJECT]
  
  (7)接收來自FTP的數據通道
  
  [/sbin/iptables -A FORWARD -p tcp -s 0/0 --sport ftp-data -d 192.168.1.0/24 -i ppp0 -j ACCEPT]
  
  (8)接收來自Internet 的UDP數據包
  
  [/sbin/iptables -A FORWARD -p udp -d 192.168.1.0/24 -i ppp0 -j ACCEPT]
  
  (9)接收來自Internet的非連接請求tcp包
  
  [ /sbin/iptables -A FORWARD -p tcp -d 192.168.1.0/24 ! -syn -i ppp0 -j ACCEPT]
  
  (10) 在前面限制的基礎上,接受來自整個Intranet的數據包過,定義如下規則:
  
  [ /sbin/iptables -A FORWARD -s 192.168.1.0/24 -i eth1 -j ACCEPT ]

[火星人 ] 用Iptables+RedHatLinux9.0做ADSL路由器已經有441次圍觀

http://coctec.com/docs/linux/show-post-204591.html