我正在尝试使用dnsmasq在小型本地网络上向我的客户推送路由。
但是我的客户端(服务器#1、#2 和#3)不能使用这些路由。dnsmasq 服务正在运行,我不知道可能出了什么问题。
这是我的“/etc/dnsmasq.conf”文件的内容:
domain-needed
bogus-priv
no-resolv
no-poll
server=/localnet/192.168.56.254
server=8.8.3.3
server=8.8.8.8
server=208.67.220.220
local=/brlightinternet.local/
interface=vboxnet0
listen-address=192.168.56.254
no-hosts
expand-hosts
domain=brlightinternet.local
dhcp-range=192.168.56.3,192.168.56.253,12h
dhcp-option=option:router,192.168.56.254
# pushing routes
dhcp-option=121,10.0.4.0/24,10.0.6.4,10.8.0.0/24,10.0.6.4,10.0.6.0/24,10.8.0.1
dhcp-option=249,10.0.4.0/24,10.0.6.4,10.8.0.0/24,10.0.6.4,10.0.6.0/24,10.8.0.1
dhcp-option=vendor:MSFT,2,1i
cache-size=150
重要提示: “192.168.56.254”不是运行 dnsmasq 的服务器的 ip。它的ip是“192.168.56.1”。据我了解,我们可以为 dnsmasq 分配不同的 ip。
这是每个客户端(服务器 #1、#2 和 #3)上的网络配置(“/etc/sysconfig/network-scripts/ifcfg-enp0s17”)...
BOOTPROTO=static
DEVICE=enp0s17
DNS1=192.168.56.254
GATEWAY=192.168.56.254
IPADDR=192.168.56.120
IPV6INIT=NO
NETMASK=255.255.255.0
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
USERCTL=NO
ZONE=public
......只有ips改变......
Server #1 -> IPADDR=192.168.56.122
Server #2 -> IPADDR=192.168.56.120
Server #3 -> IPADDR=192.168.56.121
有关每台服务器的 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: 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.122/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
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.0.2.10/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s8
valid_lft 888sec preferred_lft 888sec
inet6 fe80::2c5c:27aa:2636:8dc9/64 scope link noprefixroute
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.120/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
inet6 fe80::a00:1cff:fea6:b959/64 scope link
valid_lft forever preferred_lft forever
5: 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::6a67:7379:b64:967c/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.0.4.4/24 brd 10.0.4.255 scope global noprefixroute dynamic enp0s8
valid_lft 1115sec preferred_lft 1115sec
inet6 fe80::899f:8ca4:a7c6:25a7/64 scope link noprefixroute
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.121/24 brd 192.168.56.255 scope global noprefixroute enp0s17
valid_lft forever preferred_lft forever
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::48c2:b3cd:5845:5d35/64 scope link flags 800
valid_lft forever preferred_lft forever
注意 I:在服务器 #2 上启用了“ip_forward”...
echo -n "net.ipv4.ip_forward=1
" >> /etc/sysctl.d/ip_forward.conf
sysctl -w net.ipv4.ip_forward=1
注意二:这个线程与问题完全相关......
有了这个解决方案,我可以毫无问题地制作路线......
https://unix.stackexchange.com/a/457347/61742
...但是没有像我使用 dnsmasq 时那样集中的好处。
谢谢!=D
AFAICT
不幸的是,为 dnsmasq 提供几个 dhcp 选项会导致最后一个被应用(不是全部)。
因此,您只需提供两个 IP 地址(网络和网关):
而且,您还需要告诉每个服务器[123] 请求路由。
并且,如果您的 ISC DHCP 客户端不支持此选项(当前 Debian 中支持此选项),您需要在
/etc/dhclient.conf
or中添加如下行/etc/dhcp3/dhclient.conf
:了解
dhclient
121 选项,然后使用一些脚本/etc/dhcp3/dhclient-exit-hooks.d/configure_static_routes
使网络配置自动进行。这是一个很好的描述。