大网数据广告活动
服务器运维问答

OpenBSD: Gateway outside subnet (works in Linux)

· 52CE 我爱测

We need to set up an OpenBSD host to use a default gateway that's outside of it's subnet. This is all I need to do on Linux (not the actual IPs) to achieve it: ifconfig eth0 33.33.33.33/31 up route add 33.33.33.254 dev eth0 route…

问题原文

原帖链接 · kshade · CC BY-SA 3.0

We need to set up an OpenBSD host to use a default gateway that's outside of it's subnet. This is all I need to do on Linux (not the actual IPs) to achieve it:

ifconfig eth0 33.33.33.33/31 up
route add 33.33.33.254 dev eth0
route add default gw 33.33.33.254

The problem is that we don't know the proper equivalent of the middle command in OpenBSD. The man page says:

If the destination is directly reachable via an interface requiring no intermediary system to act as a gateway, the -iface modifier should be specified;

Sadly we can't seem to figure out how to make it work with that. This is a virtual host on an OVH server, they have documentation for many other operating systems showing how to do it here: http://help.ovh.co.uk/BridgeClient

已采纳解答

原帖链接 · mike · CC BY-SA 3.0

This is an old thread, but here goes.

As it happens, I run a number of OpenBSD VMs on an ESXi 6.0 running at SoYouStart, a daughter company of OVH. The network setup there is the same as with OVH and I think, although strange, its main purpose is to eliminate ARP traffic as much as possible by artificially limiting the broadcast domains, and without the need for using VLANs for example.

In my case, I've requested extra IP addresses from OVH and they come from a completely different range. For the discussion here, let's assume these are my settings:

  • my main IP address (which the ESXi Host is using): 213.0.113.78/32
  • the extra IP address range for VM guests: 192.0.2.64/30
  • the default gateway for ALL of the above: 213.0.113.254
  • please note - all hosts need to use a host netmask (255.255.255.255) due to the way the OVH network is configured

To configure the routing on the OpenBSD host, this is what I need to do:

ifconfig vmx0 inet 192.0.2.64 255.255.255.255 
route add -inet 213.0.113.254 -llinfo -link -static -iface vmx0 
route add -inet default 213.0.113.254

To have all this done during the start, I ignore the /etc/mygate file and put the following in the /etc/hostname.vmx0:

inet 192.0.2.64 255.255.255.255
!sleep 2
!route add -inet 213.0.113.254 -llinfo -link -static -iface vmx0
!route add -inet default 213.0.113.254

You will notice the sleep command - for some reason this is required on OpenBSD 5.9 but wasn't before. Without the sleep, the first of the to route commands will not be executed and therefore your routing will not be configured correctly.

This works using the following trick:

  • we configure the IP address on the interface
  • with the first route command we translate the IP address of the gateway (213.0.113.254) to a link address (MAC address); this is done by the -llinfo option;
  • in the same route command, using the -link option, we install the link address to the routing table and using the -iface vmx0 we tell the kernel which network interface that link address is reachable via; the -static switch marks it as a manually inserted entry into the routing table
  • the second route command can now succeed, as the route to the default gateway is now known

One thing I did come across in the setup above, which I have no solution for yet, is that one of four OpenBSD hosts, configured in the exact same way, running the exact same version of the OS and the exact same kernel build, and even running on the same VMware host, every 24 hours or so, seems to be "losing" that magic route from its routing table...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-10-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。