如果我有一个带有以下两个命令的脚本来修改路由
/ sbin / route add -host pandora.com -interface ppp0 / sbin / route add -host internal-tuner.pandora.com -interface ppp0
有没有办法用* .pandora.com之类的东西创建一个独特的命令路径?
if I have a script with the following two commands to modify a route
/sbin/route add -host pandora.com -interface ppp0 /sbin/route add -host internal-tuner.pandora.com -interface ppp0
Is there a way to create a one unique command route with something like *.pandora.com?
最满意答案
我认为答案是否定的。 使用dns名称而不是ip地址添加路由时,route命令所做的第一件事就是查找并将其转换为ip地址。 因此,如果pandora.com目前解析为172.16.0.1,那么机器真正做的是通过ppp0添加到172.16.0.1/32的路由。 当机器决定如何路由数据包时,它会使用你设置的ip地址和掩码来实现,无论你使用的域名在那个阶段都被遗忘了。
要为域中的所有计算机添加路由,您必须知道所有IP地址,这意味着您需要知道所有主机名。 如果您的DNS服务器设置为允许这种类型的东西,您可以询问它在pandora.com域中的所有内容,但现在很少有dns服务器允许这样的事情。
但是......如果你知道pandora.com中的所有内容都有一个IP地址,例如172.16.0.0和172.16.0.255(所谓的网络块,你可以使用whois获得的东西)你可以添加整个网络的路线,例如:
ip route add 172.16.0.0/24 dev ppp0另请注意,我在那里使用了iproute2命令而不是/ sbin / route。
I think the answer is no. When you add a route using the dns name instead of the ip address, the first thing the route command does is look it up and translate it to an ip address. So if pandora.com presently resolves to 172.16.0.1, then what the machine is really doing is adding a route to 172.16.0.1/32 via ppp0. When the machine decides how to route a packet, it does so using the ip addresses and masks you set up, whatever domain name you used is long forgotten at that stage.
In order to add routes for all machines in the domain, you would have to know all the ip addresses, which means you need to know all the host names already. If your DNS server is set up to allow that sort of thing, you could ask it for everything in the pandora.com domain, but very few dns servers will allow that sort of thing nowadays.
But... if you know that everything in pandora.com has an ip address starting between, for example, 172.16.0.0 and 172.16.0.255 (the so called net block, the kind of thing you can get using whois) you could add a route for the whole network, eg:
ip route add 172.16.0.0/24 dev ppp0Note also that I used the iproute2 command there rather than /sbin/route.
更多推荐
发布评论