前回(OpenVPNで会社のLANと自宅のLANを繋いでみた - yoshida_eth0の日記)は会社LANから自宅DMZへの接続が出来るようにした。
今回は、自宅クライアント用LANから、会社LANへ接続出来るようにする。
デバイスはTUNからTAPに変更した。
ネットワーク構成
自宅クライアント用LANは全部DHCPでやってるから、変えても特に問題がないので変更した。
自宅のネットワークは↓この2つ。
・192.168.0.0/24 ←DMZ
・192.168.10.0/24 ←クライアント用
会社のネットワークは↓この1つ。
・192.168.1.0./24
自宅 VPNサーバ
/etc/openvpn/server.conf
client-config-dirを使って特定のクライアントには固定のIPを割り当てるようにした。
[root@vpn ~]# cat /etc/openvpn/server.conf | grep -v "^[#;]" | grep -v "^$" port 1194 proto udp dev tap ca ca.crt cert server.crt key server.key # This file should be kept secret dh dh1024.pem server 10.8.0.0 255.255.255.0 client-config-dir ccd push "route 192.168.0.0 255.255.255.0" push "dhcp-option DNS 192.168.0.40" client-to-client duplicate-cn keepalive 10 120 tls-auth ta.key 0 # This file is secret comp-lzo user nobody group nobody persist-key persist-tun status /var/log/openvpn-status.log log-append /var/log/openvpn.log verb 3 management localhost 7505 crl-verify crl.pem
iptables
tunをtapに置き換え。
/etc/sysconfig/static-routes
any net 192.168.1.0/24 gw 10.8.0.10
社内サーバ(VPNクライアント)
/etc/openvpn/client.conf
[root@localhost ~]# cat /etc/openvpn/client.conf | grep -v '^[#;]' | grep -v '^$' client ifconfig 10.8.0.10 255.255.255.0 route 192.168.0.0 255.255.255.0 10.8.0.1 dhcp-option DNS 192.168.0.40 dev tap proto udp remote eth0.jp 1194 resolv-retry infinite nobind user nobody group nobody persist-key persist-tun ca ca.crt cert kaisha.crt key kaisha.key ns-cert-type server tls-auth ta.key 1 comp-lzo verb 3
iptables
tunをtapに置き換え。
IPマスカレードしない。
#!/bin/bash /etc/rc.d/init.d/iptables stop iptables -P INPUT ACCEPT iptables -P OUTPUT ACCEPT iptables -P FORWARD ACCEPT #iptables -t nat -A POSTROUTING -o tap0 -j MASQUERADE #iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE /etc/rc.d/init.d/iptables save /etc/rc.d/init.d/iptables start
自宅ルータ
10.8.0.0/24と192.168.1.0/24は192.168.0.41に静的ルーティング。
自宅クライアントから会社LANにtracert
C:\>tracert 192.168.1.15 Tracing route to 192.168.1.15 over a maximum of 30 hops 1 1 ms <1 ms <1 ms corega.home [192.168.10.1] 2 1 ms 1 ms 1 ms 192.168.0.1 3 2 ms 5 ms 4 ms 192.168.0.41 4 14 ms 12 ms 12 ms 10.8.0.10 5 14 ms 13 ms 12 ms 192.168.1.15 Trace complete.