问题:
我有一个包含 5 台服务器(服务器 #1、#2、#3、#4 和 #5)的基础架构。我正在尝试使用带有 ISC KEA DHCP (DHCPv4) ( https://kea.isc.org/wiki ) 的服务器 (服务器 #5) 将路由推送到其他服务器 (服务器 #1、#2、#3 和 # 4)。目标是所有服务器都可以使用服务器#2 和 3#(VPN 隧道)之间的 LAN 与其他服务器(ping
、、ssh
等)通信。
服务器:
Server #1 - DHCPv4 Client;
Server #2 - DHCPv4 Client and OpenVPN Server;
Server #3 - DHCPv4 Client and OpenVPN Client;
Server #4 - DHCPv4 Client;
Server #5 - ISC KEA DHCP (DHCPv4).
子网:
192.168.56.0/24
10.1.2.0/24
10.1.4.0/24
10.1.6.0/24
10.8.0.1/24 (VPN tunnel)
服务器设置:
注意:这里介绍的基础设施是我在 VirtualBox 上创建的用于运行测试的测试环境的一部分(不是真实环境)。例如,192.168.56.0/24 网络存在于所有服务器上。
有关每台服务器的 LAN(网络接口)的信息...
服务器 #1
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:56:84:1f brd ff:ff:ff:ff:ff:ff
inet 10.1.6.3/24 brd 10.1.6.255 scope global noprefixroute dynamic enp0s8
valid_lft 3514sec preferred_lft 3514sec
inet6 fe80::a00:27ff:fe56:841f/64 scope link
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:12:26:e2:6c brd ff:ff:ff:ff:ff:ff
inet 192.168.56.3/24 brd 192.168.56.255 scope global noprefixroute dynamic enp0s17
valid_lft 3606sec preferred_lft 3606sec
inet6 fe80::a00:12ff:fe26:e26c/64 scope link
valid_lft forever preferred_lft forever
服务器 #2
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:2c:d1:58 brd ff:ff:ff:ff:ff:ff
inet 10.1.6.4/24 brd 10.1.6.255 scope global noprefixroute dynamic enp0s8
valid_lft 3856sec preferred_lft 3856sec
inet6 fe80::a00:27ff:fe2c:d158/64 scope link
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:1c:a6:b9:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.4/24 brd 192.168.56.255 scope global noprefixroute dynamic enp0s17
valid_lft 3897sec preferred_lft 3897sec
inet6 fe80::a00:1cff:fea6:b959/64 scope link
valid_lft forever preferred_lft forever
4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
inet 10.8.0.1/24 brd 10.8.0.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::ec75:f69e:e65c:1215/64 scope link flags 800
valid_lft forever preferred_lft forever
服务器 #3
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:71:77:07 brd ff:ff:ff:ff:ff:ff
inet 10.1.4.5/24 brd 10.1.4.255 scope global noprefixroute dynamic enp0s8
valid_lft 3741sec preferred_lft 3741sec
inet6 fe80::a00:27ff:fe71:7707/64 scope link
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:ea:4e:40:ae brd ff:ff:ff:ff:ff:ff
inet 192.168.56.5/24 brd 192.168.56.255 scope global noprefixroute dynamic enp0s17
valid_lft 3766sec preferred_lft 3766sec
inet6 fe80::a00:eaff:fe4e:40ae/64 scope link
valid_lft forever preferred_lft forever
4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
inet 10.8.0.6/24 brd 10.8.0.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 fe80::6763:9d85:a754:bf0f/64 scope link flags 800
valid_lft forever preferred_lft forever
服务器#4
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:e0:d2:c8 brd ff:ff:ff:ff:ff:ff
inet 10.1.4.6/24 brd 10.1.4.255 scope global noprefixroute dynamic enp0s8
valid_lft 3907sec preferred_lft 3907sec
inet6 fe80::a00:27ff:fee0:d2c8/64 scope link
valid_lft forever preferred_lft forever
3: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:aa:e7:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.6/24 brd 192.168.56.255 scope global noprefixroute dynamic enp0s17
valid_lft 3907sec preferred_lft 3907sec
inet6 fe80::a00:27ff:feaa:e760/64 scope link
valid_lft forever preferred_lft forever
服务器 #5
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:63:ce:c5 brd ff:ff:ff:ff:ff:ff
inet 10.1.2.2/24 brd 10.1.2.255 scope global noprefixroute enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe63:cec5/64 scope link
valid_lft forever preferred_lft forever
3: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:98:ee:35 brd ff:ff:ff:ff:ff:ff
inet 10.1.4.2/24 brd 10.1.4.255 scope global noprefixroute enp0s9
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe98:ee35/64 scope link
valid_lft forever preferred_lft forever
4: enp0s10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:b6:6b:50 brd ff:ff:ff:ff:ff:ff
inet 10.1.6.2/24 brd 10.1.6.255 scope global noprefixroute enp0s10
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:feb6:6b50/64 scope link
valid_lft forever preferred_lft forever
5: enp0s17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:78:ed:d4 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.2/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe78:edd4/64 scope link
valid_lft forever preferred_lft forever
谢谢!
关于这个答案(教程):
本教程旨在展示 ISC KEA DHCP (DHCPv4) 配置和部署的“成功案例”。特别演示了向 DHCP 客户端推送路由。针对具体案例还考虑了其他要点,这些要点是为了使演示更具说教性。
在特定情况下(使用 VirtualBox 进行模拟),我们使用 OpenVPN 隧道,并演示如何在 LAN-TO-LAN 基础设施中进行路由以两种方式使用它。
本教程的构建考虑了这样一个场景:我们在 Internet 上的服务器 (Serverloft) 在 VPN 的一端运行 Hypervisor (Xen),在 VPN 的另一端运行公司 LAN,其中两个网络的所有服务器都能够以透明的方式进行沟通。
本教程中还考虑了其他注意事项,我们建议您完整阅读。
我们觉得有必要做这个教程,因为在互联网上找不到像它这样“实用”的东西。本教程还针对像我们这样对此处介绍的基本概念有更大困难的受众。
在我们继续之前,我们要感谢在此过程中提供帮助的许多人。我们特别感谢用户:@Filipe Brandenburger、@Rui F Ribeiro、@AB、@Isaac、@slm 和其他用户(不幸的是,我们不能引用每个人的话)。
本教程中的服务器:
注意:所有服务器都是 CentOS 7。
子网:
服务器 #5 - ISC KEA DHCP (DHCPv4) 服务器:
. 在 CentOS 7 上安装 ISC KEA DHCP (DHCPv4)
. 在 systemd (systemctl) 中为 KEA 服务创建设置(启动设置)...
vi '/usr/lib/systemd/system/kea-dhcp4.service'
vi '/usr/lib/systemd/system/kea-dhcp6.service'
vi '/usr/lib/systemd/system/kea-dhcp-ddns.service'
. 创建(调整)配置文件“/usr/local/etc/kea/kea-dhcp4.conf”...
vi '/usr/local/etc/kea/kea-dhcp4.conf'
. 配置网络接口
这些网络接口将为所有机器提供 DHCP 服务器(参见上面的“kea-dhcp4.conf”)。
NOTE: In a REAL WORLD SCENARIO the machines that are on the "OpenVPN server side network" would own a DHCP server and machines that are on the "OpenVPN client side network" would own another DHCP server. This division works perfectly as we are talking about the "layer 2" of the OSI model, which is therefore isolated from "layer 3" where there will be "routing", "ip forward" etc, which will be part of the integration between the two networks.
vi '/etc/sysconfig/network-scripts/ifcfg-enp0s17'
vi '/etc/sysconfig/network-scripts/ifcfg-enp0s8'
vi '/etc/sysconfig/network-scripts/ifcfg-enp0s9'
vi '/etc/sysconfig/network-scripts/ifcfg-enp0s10'
Server #2 - Client DHCPv4 and OpenVPN Server:
. OpenVPN server settings
vi '/etc/openvpn/server/server.conf'
IMPORTANT: We are only considering the CONFIGURATIONS STRICTLY NECESSARY FOR THE OPENVPN OPERATION IN THE PROPOSED INFRASTRUCTURE ("server.conf" and "client0"). Other settings are required. For more information, check out the OpenVPN documentation. More details on the needs addressed here at this link https://openvpn.net/index.php/open-source/documentation/howto.html#scope .
. OpenVPN client settings
NOTE: These settings are consumed by the client on the server side.
vi '/etc/openvpn/ccd/client0'
Server #3 - Client DHCPv4 and OpenVPN Client
. OpenVPN client settings
vi '/etc/openvpn/client/client0.conf'
Server #2 e #3:
. Open the firewall for "OpenVPN" (Server #2 and #3)
NOTE: Openvpn is not the focus of the thread so we will not go into details here!
. Enable "ip_forward" (Server #2 and #3)
Server #1, #2, #3 e #4:
. Configure network interfaces
vi '/etc/sysconfig/network-scripts/ifcfg-enp0s8'
NOTE: All interfaces in all machines follow this same model since the network configurations will be provided by Server #5 (KEA DHCP Server).
vi '/etc/sysconfig/network'
Test:
. This tutorial will have been successfully executed if all of these tests are positive:
Tips:
Internet (WAN) test
Renew DHCP on clients
Remove DHCP leases settings from clients:
NOTE: Important to test the operation of the DHCP server.
Remove DHCP leases settings from server:
NOTE: Important to test the operation of the DHCP server.
Other guidelines:
General guidelines and about the environment used for this tutorial:
This configuration tutorial was built in a test environment using VirtualBox;
All networks in use are "Host-only" and one of them (192.168.56.0/24) has internet (see 3). None of them should have VirtualBox DHCP enabled;
By default "Host-only" networks have no internet access ( https://www.virtualbox.org/manual/ch06.html#networkingmodes ). However, in this tutorial https://forum.manjaro.org/t/manjaro-and-virtualbox-host-only-with-internet/28722/12 I teach how to "circumvent" this limitation;
The internet (WAN) for the 192.168.56.0/24 network must be activated only when it is necessary. Must be disabled for running tests except to check internet access (
curl http://www.google.com
) on Servers #1, #2, #3 and #4 (see 3);Services such as "dnsmasq" and "iptables" should be disabled on the host when the network tests are executed (ping, ssh, etc) (see 3);
Generally speaking, no DHCP should be present on layer 2 of the networks during the tests except what is on Server #5.
Use tun or tap (OpenVPN) - A Discussion:
We transpose below part of a chat ( chat.stackexchange.com ) between @Eduardo Lucio and @Isaac about the deploy model in this answer. We ( @Eduardo Lucio ) opted, at the moment, for using "tun", even though it was a "more laborious" configuration. However if you want a truly transparent integration between the networks on both sides of the VPN opt for tap (with all its pros and cons). I believe that the clarifications of @Isaac are very relevant to decide what to use (tap or tun) and so are transposed here so that it can reach more people.