Network setup default route with a different source?

I need help setting up network and routing on a VM running proxmox at OVH.

The OVH documentation give a linux example that doesn't translate to FreeBSD:

I've tried to find the answer in the freebsd handbook, but it mostly covers use cases for gateways/routers.

VM hosts are on a proxmox software bridge with a gateway of 192.168.0.1
My assigned IP is: 51.79.123.123

My Freebsd host is 192.168.0.123 and can ping the proxmox machine at 192.168.0.1.
All outgoing traffic to/from the internet is supposed to go through the 192.168.0.1 gateway

rc.conf has the following:
hostname="myhostname.mydomainname.com"
defaultrouter="192.168.0.1"
ifconfig_vtnet0="inet 192.168.0.123 netmask 0xffffff00"
ifconfig_vtnet0_alias0="inet 51.79.123.123 netmask 0xffffffff"
static_routes="net1 net2"
route_net1="-net 51.79.123.123/32 -iface vtnet0"
route_net2="default 192.168.0.1"

Any ideas?

Thanks
 
  1. You can set your netmask as prefix list. no need for hex conversion. For example:
    ifconfig_vtnet0="inet 192.168.0.123/24"
  2. I can not understand your question. But, If you want to use your public ip address in another subnet (like people who use /32 as their ip address. You can do the following:
sysrc ifconfig_vtnet0="inet 51.79.123.123/32"
route -4 add -host 192.168.0.1 -iface vtnet0
route -4 add default -gateway 192.168.0.1
 
I might understand what you're looking for.. but.. ?

You have thr IPv4 address on the VM 192.168.0.123 with the gw 192.168.0.1
You also have the IPv4 address on the VM as an alias on the same NIC: 51.79.123.123
My question is, what’s the gateway on the 51.79.123.0 network?

In your config you have the same IP address on the VM and as the GW, witch is wrong.

Code:
defaultrouter="192.168.0.1"
static_routes="gw2"
route_gw2="-net 51.79.123.0/24 51.79.123.1"    

ifconfig_vtnet0="inet 192.168.0.123 netmask 255.255.255.0"
ifconfig_vtnet0_alias0="inet 51.79.123.123 netmask 255.255.255.0"

That may work.
Here I have the GW on .1 (51.79.123.1), you need to set the correct GW.
 
If you want to use your FreeBSD VM as a router, add more interfaces. Put the 51.x.x.x. address (your 'external' internet address I presume?) on one interface, and the 192.168.0.1/24 address on a second interface. Do NOT put both your external and internal addresses on the same interface.
 
If you want to use your FreeBSD VM as a router, add more interfaces. Put the 51.x.x.x. address (your 'external' internet address I presume?) on one interface, and the 192.168.0.1/24 address on a second interface. Do NOT put both your external and internal addresses on the same interface.
Oooo.. He wanted a router!!!
Yhea, when my conf is not the way to go. He need 2 NICs with gateway_enable="YES" etc.
 
Back
Top