[root]# rpm -q iptables iptables-1.2.7a-0vl1 [root]# rpm -q ipchains ipchains-1.3.10-0vl3 [root]# |
[root]# lsmod Module Size Used by Tainted: P iptable_mangle 2880 0 (unused) iptable_nat 25012 0 (unused) ip_conntrack 30868 1 [iptable_nat] iptable_filter 2432 0 (autoclean) (unused) ip_tables 15712 5 [iptable_mangle iptable_nat iptable_filter] |
[root]# modprobe iptable_nat [root]# modprobe iptable_mangle |
[root]# modprobe -l |
[root]# modprobe -l | grep -i ip |
[root]# chkconfig --list network 0:off 1:off 2:on 3:on 4:on 5:on 6:off inet 0:off 1:off 2:off 3:on 4:on 5:on 6:off ipchains 0:off 1:off 2:off 3:off 4:off 5:off 6:off iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off routed 0:off 1:off 2:off 3:off 4:off 5:off 6:off adsl 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root]# |
[root]# chkconfig --del ipchains |
[root]# chkconfig --add ipchains [root]# chkconfig --level 2345 ipchains on |
[root]# apt-get install rp-pppoe |
[root]# adsl-start .. Connected! [root]# adsl-status adsl-status: Link is up and running on interface ppp0 ppp0 リンク方法:Point-to-Pointプロトコル inetアドレス:202.233.233.125 P-t-P:133.160.135.246 マスク:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1454 Metric:1 RX packets:3 errors:0 dropped:0 overruns:0 frame:0 TX packets:3 errors:0 dropped:0 overruns:0 carrier:0 衝突(Collisions):0 TXキュー長:3 RX bytes:30 (30.0 b) TX bytes:30 (30.0 b) [root]# adsl-stop Killing pppd (2819) Killing adsl-connect (2791) [root]# adsl-status adsl-status: Link is down (can't read pppoe PID file /var/run/pppoe.conf-adsl.pid.pppoe) [root]# |
[root]# chkconfig --add adsl [root]# chkconfig --level 2345 adsl on [root]# chkconfig --list adsl adsl 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root]# |
[root]# chkconfig --del adsl [root]# chkconfig --add adsl [root]# chkconfig --level 2345 adsl on |
[root]# iptables -F [root]# iptables -X |
iptables -P INPUT ACCEPT |
[root]# iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination [root]# |
#!/bin/sh #iptablesコマンド使った firewallの設定スクリプト LOCAL_NET='192.168.0.0/16' CLIENT_A='192.168.0.2' #基本ポリシー (-Pオプション)の設定 #INPUTは拒否 DROP #OUTPUTは許可 ACCEPT #FORWARDは拒否 DROP # iptables -P INPUT DROP iptables -P OUTPUT ACCEPT (DROPが基本というサイトが大多数です、念のため) iptables -P FORWARD DROP #個別ルールを全削除 # iptables -F iptables -t nat -F #ユーザー定義チェインを削除 # iptables -X #ループバックに関してはすべて許可 # iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT #自分が発するコマンドを許可 # #iptables -A INPUT -i lo -j ACCEPT #(この設定はセキュリティー上良くなかった?) #(次の行の設定に変更しました) iptables -A INPUT -s 192.168.0.25 -d 192.168.0.25 -j ACCEPT #eth0から入ってくる LOCAL NET PCからの通信を許可 # iptables -A INPUT -i eth0 -p all -s $LOCAL_NET -j ACCEPT # 発信元が loop back private addressのパケットを拒否 # iptables -A INPUT -i ppp0 -s 127.0.0.0/8 -j DROP iptables -A INPUT -i ppp0 -s 10.0.0.0/8 -j DROP iptables -A INPUT -i ppp0 -s 176.16.0.0/12 -j DROP iptables -A INPUT -i ppp0 -s 192.168.0.0/16 -j DROP # TCP PORT 80,8080の通過を許可 # iptables -A INPUT -i ppp0 -p tcp --dport 80 -j ACCEPT iptables -A INPUT -i ppp0 -p tcp --dport 8080 -j ACCEPT iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # PORT 135 rpc # 137 netbios # 138 netbios # 139 file/printer共有 # 445 file/printer共有 # ppp0へ向けて出て行く以上のパケットは DROP # iptables -A FORWARD -p udp -i eth0 -o ppp0 --dport 135:139 -j DROP iptables -A FORWARD -p tcp -i eth0 -o ppp0 --dport 135:139 -j DROP iptables -A FORWARD -p udp -i eth0 -o ppp0 --dport 445 -j DROP iptables -A FORWARD -p tcp -i eth0 -o ppp0 --dport 445 -j DROP # 送信先が LOCAL ADDRESSの物が ppp0へ向けて出て行ったら DROP # iptables -A FORWARD -o ppp0 -d 192.168.0.0/16 -j DROP #eth0からeth1へ向けてのパケットは許可 # iptables -A FORWARD -i eth0 -o ppp0 -s $LOCAL_NET -j ACCEPT iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT # LANから外に出て行くパケットの送信元IPを書き換え # iptables -t nat -A POSTROUTING -o ppp0 -s $LOCAL_NET -j MASQUERADE # ループバック宛、プライベートアドレス宛のパケットが漏れるのを防ぐ # iptables -A OUTPUT -o ppp0 -d 127.0.0.0/8 -j DROP iptables -A OUTPUT -o ppp0 -d 10.0.0.0/8 -j DROP iptables -A OUTPUT -o ppp0 -d 176.16.0.0/12 -j DROP iptables -A OUTPUT -o ppp0 -d 192.168.0.0/16 -j DROP # NetBIOS over TCP/IP の流出パケットを遮断 # iptables -A OUTPUT -o ppp0 -p tcp --dport 135:139 -j DROP iptables -A OUTPUT -o ppp0 -p udp --dport 135:139 -j DROP iptables -A OUTPUT -o ppp0 -p tcp --dport 445 -j DROP iptables -A OUTPUT -o ppp0 -p udp --dport 445 -j DROP |
chmod 744 firewall-setting.sh |
[root]# iptables-save > /etc/sysconfig/iptables |
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway |
最初の状態。 WIN PCの Networkアドレスは 192.168.0.2 通常使っている routerのアドレスは 192.168.0.1 テスト中の linux pcのアドレスは 192.168.0.5 > route print =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.2 1 127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1 192.168.0.0 255.255.255.0 192.168.0.2 192.168.0.2 1 192.168.0.2 255.255.255.255 127.0.0.1 127.0.0.1 1 192.168.0.255 255.255.255.255 192.168.0.2 192.168.0.2 1 224.0.0.0 224.0.0.0 192.168.0.2 192.168.0.2 1 255.255.255.255 255.255.255.255 192.168.0.2 192.168.0.2 1 Default Gateway: 192.168.0.1 =========================================================================== > route DELETE 0.0.0.0 とやると Default Gatewayが消える =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1 192.168.0.0 255.255.255.0 192.168.0.2 192.168.0.2 1 192.168.0.2 255.255.255.255 127.0.0.1 127.0.0.1 1 192.168.0.255 255.255.255.255 192.168.0.2 192.168.0.2 1 224.0.0.0 224.0.0.0 192.168.0.2 192.168.0.2 1 255.255.255.255 255.255.255.255 192.168.0.2 192.168.0.2 1 =========================================================================== > route ADD 0.0.0.0 192.168.0.5 MASK 0.0.0.0 とやると =========================================================================== Active Routes: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.0.5 192.168.0.2 1 127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1 192.168.0.0 255.255.255.0 192.168.0.2 192.168.0.2 1 192.168.0.2 255.255.255.255 127.0.0.1 127.0.0.1 1 192.168.0.255 255.255.255.255 192.168.0.2 192.168.0.2 1 224.0.0.0 224.0.0.0 192.168.0.2 192.168.0.2 1 255.255.255.255 255.255.255.255 192.168.0.2 192.168.0.2 1 Default Gateway: 192.168.0.5 =========================================================================== コマンド一発で Default Gatewayの設定を変えることが出来る。 |
#!/bin/sh iptables -P INPUT ACCEPT iptables -F iptables -X iptables -nL |