Linux(CentOs5)でつくってるルータのメモ †下記のようなLANおよびインターネットアクセス環境を構築中の②のとこの話 ① ② ③ WiFi -------[flet's router]----------+-------- [LinuxRouter] -------------+-------- [無線LANルータ] <===============> [無線LANクライアント] global ip/192.168.24.1 | 192.168.24.201/192.168.25.1 | 192.168.25.2/192.168.182.1 192.168.182.*/24 | | | | : +------- PCs : +------- SIP phones --2F : : | 192.168.24.51- : | 192.168.25.121- : : | : | : : +------- Servers : +------ SIP phones --3F : : | 192.168.24.202- : | 192.168.25.131- : : | : | : : +------- IPPhone : +------- PCs : : 192.168.24.2 : 192.168.25.51- : : : : : : : internet -----> : <--------- 192.168.24.0/24 ---------> : <---------- 192.168.25.0/24 ------------> : <-------- 192.168.182.0/24 : : : 無線ルータはこの位置の必要ないかなぁ。 Ethernetの設定 †eth0/eth1はデフォルトで認識されたのでここでは設定は省略。 routeの設定 †デフォルトゲートウェイを 192.168.24.1としてrouteの設定は下記のようになっている。 #route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.25.0 * 255.255.255.0 U 0 0 0 eth1 192.168.24.0 * 255.255.255.0 U 0 0 0 eth0 default 1.24.168.192.in 0.0.0.0 UG 0 0 0 eth0 ②のLinux Routerの設定 †iptablesが入ってないければインストール #yum install iptables もし、iptablesがすでに動いているようであれば、まず止めておく。 #/etc/init.d/iptables stop iptablesの設定 †あとで変更したい場合もあるので、iptablesの設定をシェルスクリプトにしておく。 iptables設定方針として INPUT(入ってくるもの)は原則破棄。必要なものだけ許可。 OUTPUT(出ていくもの)は原則許可。必要なものだけ破棄。 FORWARD(中継するもの)は原則許可。必要なものだけ破棄。 とする。 #!/bin/sh ################################################ # IP Forward を有効にする echo 1 > /proc/sys/net/ipv4/ip_forward ################################################ # ルールをクリア iptables -F iptables -t nat -F ################################################ # ポリシーの設定 # INPUTは原則破棄。必要なもののみ許可。 # OUTPUT、FORWARDは原則許可。不要なもののみ破棄。 iptables -P INPUT DROP iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT ################################################ # INPUT ## プロトコル別 # icmp許可 iptables -A INPUT -p icmp -j ACCEPT # http許可 iptables -A INPUT -p tcp --dport 80 -j ACCEPT # smtp許可 iptables -A INPUT -p tcp --dport 25 -j ACCEPT # ssh許可 iptables -A INPUT -p tcp --dport 22 -j ACCEPT # dnsアクセス許可 #iptables -A INPUT -p tcp --dport 53 -j ACCEPT #iptables -A INPUT -p udp --dport 53 -j ACCEPT # SIP電話アクセス許可 #iptables -A INPUT -p tcp --dport 5060 -j ACCEPT ## アクセス元別 # localhostからのアクセス許可 iptables -A INPUT -i lo -j ACCEPT # LAN(192.168.24.0/24)からのアクセス許可 iptables -A INPUT -i eth0 -s 192.168.24.0/24 -j ACCEPT # LAN(192.168.25.0/24)からのアクセス許可 #iptables -A INPUT -i eth1 -s 192.168.25.0/24 -j ACCEPT # 接続が確立したパケットの応答は許可(つまり内部から外部へつないだ場合など) iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ################################################ # FORWARD # 宛先ポート135,137~139,445(NetBIOS系)のパケット破棄 iptables -A FORWARD -p tcp --dport 135 -j DROP iptables -A FORWARD -p udp --dport 135 -j DROP iptables -A FORWARD -p tcp --dport 137:139 -j DROP iptables -A FORWARD -p udp --dport 137:139 -j DROP iptables -A FORWARD -p tcp --dport 445 -j DROP iptables -A FORWARD -p udp --dport 445 -j DROP # パスMTU問題対策 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu ################################################ # IPマスカレード iptables -t nat -A POSTROUTING -o eth0 -s 192.168.25.0/24 -j MASQUERADE ################################################ # OUTPUT # 宛先ポート135,137~139,445(NetBIOS系)のパケット破棄 iptables -A OUTPUT -o ppp0 -p tcp --dport 135 -j DROP iptables -A OUTPUT -o ppp0 -p udp --dport 135 -j DROP iptables -A OUTPUT -o ppp0 -p tcp --dport 137:139 -j DROP iptables -A OUTPUT -o ppp0 -p udp --dport 137: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 ################################################ # logging #iptables -N LOGGING #iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit #iptables -A LOGGING -j DROP #iptables -A INPUT -j LOGGING #iptables -A FORWARD -j LOGGING ################################################ # 設定保存用 #/etc/init.d/iptables save 上記のスクリプトを実行し、保存する。 #**スクリプトファイル名** #/etc/init.d/iptables save で、iptablesを実行。 #/etc/init.d/iptables start ②のdhcpdの設定 †②の192.168.25.0/24上ではこのルータがDHCPサーバになるので、dhcpdをインストールしておく必要がある。 #yum install dhcp /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; #not authoritative; subnet 192.168.25.0 netmask 255.255.255.0 { # --- default gateway option routers 192.168.25.1; option subnet-mask 255.255.255.0; #option nis-domain "domain.org"; #option domain-name "domain.org"; option domain-name-servers 220.220.248.1,220.220.248.9; option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range dynamic-bootp 192.168.25.2 192.168.25.254; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address #host ns { # next-server marvin.redhat.com; # hardware ethernet 12:34:56:78:AB:CD; # fixed-address 207.175.42.254; #} } これを実行してみる。 #/etc/init.d/dhcpd start うまく動くようであれば OS起動時にサービスを実行したいので #chkconfig dhcpd on しておく。 |