DHCPサーバーで社内とゲストのセグメントをわける方法
30 3 月 2009
DHCPサーバーで社内とゲストのセグメントをわける方法
今回設定するのは、DHCPサーバーです。 セキュリティを考慮して、 社内PCは共有可能にし、ゲストPCには、インターネットのみを提供するようにします。 ネットワークは、 社内ネットワーク = 192.168.1.0/255.255.255.0 ゲストネットワーク = 192.168.2.0/255.255.255.0 で設定しています。自分の環境に置き換えて読んでください。 参考にしたサイトは、dhcp / iptables を組み合わせた仮想的なネットワーク分離 です。まず、DHCPをインストールします。 # yum -y install dhcp # rpm -ql dhcp /etc/dhcpd.conf /etc/rc.d/init.d/dhcpd /etc/rc.d/init.d/dhcrelay /etc/sysconfig/dhcpd /etc/sysconfig/dhcrelay /usr/bin/omshell /usr/sbin/dhcpd /usr/sbin/dhcrelay /usr/share/doc/dhcp-3.0.5 /usr/share/doc/dhcp-3.0.5/IANA-arp-parameters /usr/share/doc/dhcp-3.0.5/README /usr/share/doc/dhcp-3.0.5/RELNOTES /usr/share/doc/dhcp-3.0.5/api+protocol /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample ← 設定ファイルのサンプル /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-authentication-14.txt /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-dhcp-dns-12.txt /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-failover-07.txt /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient-script.8 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.8 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.conf.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.leases.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-eval.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-options.5 /usr/share/doc/dhcp-3.0.5/rfc1542.txt /usr/share/doc/dhcp-3.0.5/rfc2131.txt /usr/share/doc/dhcp-3.0.5/rfc2132.txt /usr/share/doc/dhcp-3.0.5/rfc2485.txt /usr/share/doc/dhcp-3.0.5/rfc2489.txt /usr/share/doc/dhcp-3.0.5/rfc951.txt /usr/share/man/man1/omshell.1.gz /usr/share/man/man5/dhcpd-eval.5.gz /usr/share/man/man5/dhcpd-options.5.gz /usr/share/man/man5/dhcpd.conf.5.gz /usr/share/man/man5/dhcpd.leases.5.gz /usr/share/man/man8/dhcpd.8.gz /usr/share/man/man8/dhcrelay.8.gz /var/lib/dhcpd /var/lib/dhcpd/dhcpd.leases 設定ファイルのサンプルをコピーして 設定ファイルを編集します。 # cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf # vi /etc/dhcpd.conf -------------------- ここから -------------------- ddns-update-style interim; ignore client-updates; # サブネットマスクに注意 subnet 192.168.0.0 netmask 255.255.0.0 { # 以下 2行を追加 社内ネットワーク用 pool { deny unknown-clients; # --- default gateway # 以下、ルーター経由の場合は、ルーターのIPアドレス # サーバーがルーターの場合は、サーバーのIPアドレス option routers 192.168.1.1; # サブネットマスクに注意 option subnet-mask 255.255.255.0; # 以下 2行をコメントアウト #option nis-domain "domain.org"; #option domain-name "domain.org"; # 以下、ルーター経由の場合は、ルーターのIPアドレス # サーバーがルーターの場合は、プロバイダのDNSアドレスをカンマ区切りで option domain-name-servers 192.168.1.1; #option domain-name-servers XXX.XXX.XXX.XXX,XXX.XXX.XXX.XXX; 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; # 以下 DHCPを割り振るIPアドレスの範囲を指定 社内ネットワーク用 range dynamic-bootp 192.168.1.128 192.168.1.254; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address # 以下 5行をコメントアウト # host ns { # next-server marvin.redhat.com; # hardware ethernet 12:34:56:78:AB:CD; # fixed-address 207.175.42.254; # } # 以下 ホスト名 shanai_client1 を指定。社内ネットワーク用 host shanai_client1 { # 以下 shanai_client1 の MACアドレスを指定。 hardware ethernet xx:xx:xx:xx:xx:xx; # 以下 shanai_client1 の IPアドレスを指定。 fixed-address 192.168.1.10; } # 以下 クライアント数分指定する。 host shanai_client2 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.1.11; } host shanai_client3 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.1.12; } ・ ・ host shanai_client150 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.1.149; } # 以下 11行を追加 ゲストPC用 # DHCPを割り振るIPアドレスの範囲と、サブネットマスクに注意 # routers と domain-name-servers は適当に、後で設定ファイルを作成します。 } pool { allow unknown-clients; range dynamic-bootp 192.168.2.1 192.168.2.127; option subnet-mask 255.255.255.0; option broadcast-address 192.168.2.255; option routers 192.168.2.254; option domain-name-servers 192.168.2.254; default-lease-time 300 ; max-lease-time 300 ; } } -------------------- ここまで -------------------- # routers と domain-name-servers で指定したアドレスを登録します。 # vi /etc/sysconfig/network-scripts/ifcfg-eth0:0 -------------------- ここから -------------------- DEVICE=eth0:0 BROADCAST=192.168.2.255 IPADDR=192.168.2.254 # 先ほどのIPアドレスを指定 NETMASK=255.255.255.0 # サブネットマスクに注意 NETWORK=192.168.2.0 GATEWAY=192.168.1.1 # サーバーのデフォルトゲートウェイを指定 BOOTPROTO=static TYPE=Ethernet ONBOOT=yes -------------------- ここまで -------------------- # ifup eth0:0 # ifconfig eth0 Link encap:Ethernet HWaddr 12:34:56:78:ab:cd inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:44001087 errors:0 dropped:0 overruns:0 frame:0 TX packets:79897496 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:4011600638 (3.7 GiB) TX bytes:2336497570 (2.1 GiB) Base address:0xd000 Memory:e8000000-e8020000 eth0:0 Link encap:Ethernet HWaddr 12:34:56:87:ab:ce inet addr:192.168.2.254 Bcast:192.168.2.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Base address:0xd000 Memory:e8000000-e8020000 # /etc/rc.d/init.d/dhcpd start ← DHCPサーバー起動 dhcpd を起動中: [ OK ] # chkconfig dhcpd on ← DHCPサーバー自動起動設定 # chkconfig --list dhcpd ← DHCPサーバー自動起動設定確認 dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← ランレベル2~5のonを確認 次にファイヤーウォールを設定します。 IPTABLEに関しては、かなりの知識が要りますので、登録情報の確認方法は、さんの 6. サーバー公開前のセキュリティ強化 の中の 4. ファイアウォール構築(iptables) を参照してください。 そこの一部分をちょっとだけ変えて使用します。 ※ 勝手に変えてすいません。 変えるところは、 # vi iptables.sh #!/bin/bash #---------------------------------------# # 設定開始 # #---------------------------------------# # インタフェース名定義 LAN=eth0 #---------------------------------------# # 設定終了 # #---------------------------------------# # 内部ネットワークのネットマスク取得 -------------------- ここから -------------------- #LOCALNET_MASK=`ifconfig $LAN|sed -e 's/^.*Mask:\([^ ]*\)$/\1/p' -e d` LOCALNET_MASK=255.255.0.0 # 内部ネットワークアドレス取得 #LOCALNET_ADDR=`netstat -rn|grep $LAN|grep $LOCALNET_MASK|cut -f1 -d' '` LOCALNET_ADDR=192.168.0.0 -------------------- ここまで -------------------- LOCALNET=$LOCALNET_ADDR/$LOCALNET_MASK ネットワークアドレスと、サブネットマスクに注意です。 あとは、
さんの 6. サーバー公開前のセキュリティ強化 の中の 4. ファイアウォール構築(iptables) にそってやってみてください。 設定は以上です。
社内ネットワークの場合 /etc/dhcpd.conf に自分のPCを登録して、DHCPにてアドレスを取得する。 # vi /etc/dhcpd.conf host shanai_client2 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.1.11; } # /etc/rc.d/init.d/dhcpd restart ← DHCPサーバー起動 dhcpd を停止中: [ OK ] dhcpd を起動中: [ OK ] Windowsであれば、コマンドにて ipconfig /release ipconfig /renew ipconfig /all を実行 Connection-specific DNS Suffix . : Description . . . . . . . . . . . : XXXXXXXXXXXXXXXXX Physical Address. . . . . . . . . : XX-XX-XX-XX-XX-XX Dhcp Enabled. . . . . . . . . . . : Yes ← DHCPサーバーが有効であることを示す Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.1.11 ← DHCPサーバーから割り当てられたIPアドレス Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 ← DHCPサーバーから割り当てられたルーターのIPアドレス DHCP Server . . . . . . . . . . . : 192.168.1.1 ← DHCPサーバーのIPアドレスが返ってくるので確認 DNS Servers . . . . . . . . . . . : 192.168.1.1 ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス クライアントが、Linuxであれば # vi /etc/sysconfig/network-scripts/ifcfg-eth0 ← ネットワーク設定ファイル編集 DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp # /etc/rc.d/init.d/network reload # ifconfig eth0 ← IPアドレス割当て状況確認 eth0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0 ← DHCPサーバーから割り当てられたIPアドレス # cat /etc/resolv.conf | grep nameserver ← 問合せ先DNSサーバーのIPアドレス確認 nameserver XXX.XXX.XXX.XXX ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス # route -n ← ルーターのIPアドレス確認 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0 ← DHCPサーバーから割り当てられたルーターのIPアドレス >ping 192.168.1.1 ← サーバーにping送信 Pinging 192.168.1.1 with 32 bytes of data: Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms >ping 192.168.1.10 ← client1にping送信 Pinging 192.168.1.10 with 32 bytes of data: Reply from 192.168.1.10: bytes=32 time<1ms TTL=128 Reply from 192.168.1.10: bytes=32 time<1ms TTL=128 Reply from 192.168.1.10: bytes=32 time<1ms TTL=128 Reply from 192.168.1.10: bytes=32 time<1ms TTL=128 Ping statistics for 192.168.1.10: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms >ping 192.168.2.254 ← DHCPサーバーのルーターにping送信 Pinging 192.168.2.254 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.168.2.254: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), ゲストネットワークにはping送信ができないことの確認。 ゲストPCの場合 /etc/dhcpd.conf 内の自分のPCをコメントアウトして、DHCPにてアドレスを取得する。 # vi /etc/dhcpd.conf # host shanai_client2 { # hardware ethernet xx:xx:xx:xx:xx:xx; # fixed-address 192.168.1.11; # } # /etc/rc.d/init.d/dhcpd restart ← DHCPサーバー起動 dhcpd を停止中: [ OK ] dhcpd を起動中: [ OK ] Windowsであれば、コマンドにて ipconfig /release ipconfig /renew ipconfig /all を実行 Connection-specific DNS Suffix . : Description . . . . . . . . . . . : XXXXXXXXXXXXXXXXX Physical Address. . . . . . . . . : XX-XX-XX-XX-XX-XX Dhcp Enabled. . . . . . . . . . . : Yes ← DHCPサーバーが有効であることを示す Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.2.127 ← DHCPサーバーから割り当てられたIPアドレス Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.2.254 ← DHCPサーバーから割り当てられたルーターのIPアドレス DHCP Server . . . . . . . . . . . : 192.168.1.1 ← DHCPサーバーのIPアドレスが返ってくるので確認 DNS Servers . . . . . . . . . . . : 192.168.2.254 ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス クライアントが、Linuxであれば # vi /etc/sysconfig/network-scripts/ifcfg-eth0 ← ネットワーク設定ファイル編集 DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp # /etc/rc.d/init.d/network reload # ifconfig eth0 ← IPアドレス割当て状況確認 eth0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX inet addr:192.168.2.127 Bcast:192.168.2.255 Mask:255.255.255.0 ← DHCPサーバーから割り当てられたIPアドレス # cat /etc/resolv.conf | grep nameserver ← 問合せ先DNSサーバーのIPアドレス確認 nameserver 192.168.2.254 ← DHCPサーバーから割り当てられたDNSサーバーのIPアドレス # route -n ← ルーターのIPアドレス確認 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 192.168.2.254 0.0.0.0 UG 0 0 0 eth0 ← DHCPサーバーから割り当てられたルーターのIPアドレス >ping 192.168.1.1 ← サーバーにping送信 Pinging 192.168.1.1 with 32 bytes of data: Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Reply from 192.168.1.1: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.1.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms >ping 192.168.1.10 ← client1にping送信 Pinging 192.168.1.10 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out. Ping statistics for 192.168.1.10: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss), >ping 192.168.2.254 ← DHCPサーバーのルーターにping送信 Pinging 192.168.2.254 with 32 bytes of data: Reply from 192.168.2.254: bytes=32 time<1ms TTL=64 Reply from 192.168.2.254: bytes=32 time<1ms TTL=64 Reply from 192.168.2.254: bytes=32 time<1ms TTL=64 Reply from 192.168.2.254: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.2.254: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms 社内ネットワークにはping送信ができないことの確認。
Comments are closed.

