# Help with routing



## balanga (Apr 27, 2018)

Can anyone point me to a guide for configuring routing between two interfaces?

I've had a brief look at the Handbook but could do with a simple step by step guide. I have a system (A) with two interfaces - one (em0) is connected to the LAN, the other (ue0) has a direct connection to the internet. How do I tell a second system (B) to access the Internet via (A) rather than via normal (pfSense) router (192.168.1.1) which also acts as a DHCP server?


----------



## PacketMan (Apr 27, 2018)

Before you try to implement routing in FreeBSD, might I suggest you find a good 'Introduction to IP Routing Fundamentals" book or document?  Cisco made one years ago and its still relevant.  Then doing routing on any machine (Cisco, Juniper, FreeBSD, Ubuntu, etc) will be that much easier.


----------



## VladiBG (Apr 27, 2018)

To configure a routing is easy just enable it with
`sysrc gateway_enable="YES"`

Then you need to NAT traffic from internal network to external network through external interface (ue0). You can do this using IPFW or PF.
`sysrc firewall_enable="YES"
sysrc firewall_type="open"
sysrc firewall_nat_enable="YES"
sysrc firewall_nat_interface="ue0"
sysrc firewall_nat_flags="same_ports reset"`

When you understand how IPFW is working you can set your own ruleset for the firewall and change it.

Then you will need a DHCP and some DNS forwarder or you can use your ISP provided DNS server.


----------



## PacketMan (Apr 27, 2018)

I don't believe he wants to do NAT on his A and/or B nodes. He has a pfSense machine to do the NAT and be the default router to the Internet.  Currently both A & B nodes send their packets directly to the pfSense node, and they do that because they know their default route is to the pfSense node, and they get that info via DHCP.

If I understand Balanga right, he wants packets leaving node B to do to node A first, and from there node B will route the packets to the pfSense node. So he can override the DHCP learned info by putting an entry in /etc/rc.conf. But in my opinion there are all sorts of design reasons why you would want (and want not) to do this.  Which is why I said what I said in my first post.


----------



## balanga (Apr 28, 2018)

If I have two interfaces, say em0 and ue0 and I want to compare the results of speedtest how would I route the program towards a particular interface?


----------



## VladiBG (Apr 28, 2018)

Change your default gateway or check the IP address of the speedtest server against you run the test and the web site then create a static route to it through specific gateway.






```
$ netstat -r
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            ISP1               UGS         0 85215527   em0
192.0.2            link#1             UC          0        0   em0
198.52.100         link#2             UC          0        0   ue0
testbox            xx:xx:xx:xx:xx:xx  UHLW        2  5232731   lo0
203.0.113.1        198.52.100.1       UGHS        0 93357355   ue0
```


----------



## Oko (Apr 28, 2018)

PacketMan said:


> Before you try to implement routing in FreeBSD, might I suggest you find a good 'Introduction to IP Routing Fundamentals" book or document?  Cisco made one years ago and its still relevant.  Then doing routing on any machine (Cisco, Juniper, FreeBSD, Ubuntu, etc) will be that much easier.


https://web.stanford.edu/class/ee384a/files/Introduction_to_IP_Multicast_Routing.pdf


----------



## PacketMan (Apr 28, 2018)

Oko said:


> https://web.stanford.edu/class/ee384a/files/Introduction_to_IP_Multicast_Routing.pdf



Why a document on multicast? Did you pick the wrong one?


----------



## Oko (Apr 28, 2018)

Yes i can't find other class notes now.


----------



## balanga (Apr 29, 2018)

VladiBG said:


> Change your default gateway or check the IP address of the speedtest server against you run the test and the web site then create a static route to it through specific gateway.
> 
> View attachment 4769
> 
> ...




How do I temporarily change the default gateway to the ue0 interface?


----------



## VladiBG (Apr 29, 2018)

First check your current default gateway and write it down.
`# netstat -rn`
To change your default gateway use:
`# route change default A.B.C.D`

You may need to change and your nameserver in /etc/resolv.conf  some ISP restrict the DNS queries only to they local subnets. So after you change to the other ISP on ue0 your current DNS server may not work. So you can use some public nameserver like 8.8.8.8


----------



## balanga (Apr 29, 2018)

It would be really hand to try and script this rather than manually entering commands... But I guess I need to be able to extract the IP address of the new interface....

Maybe something like:-

```
echo route change default `ifconfig ue0 | grep inet | awk '{print $2}'`
```


----------



## VladiBG (Apr 29, 2018)

you can't do this. This will return your ip address of the ue0 interface.


----------



## phoenix (Apr 29, 2018)

balanga said:


> It would be really hand to try and script this rather than manually entering commands... But I guess I need to be able to extract the IP address of the new interface....
> 
> Maybe something like:-
> 
> ...



If you search the forums, vermaden (I believe) has a network management script that automated a lot of things along these lines.

Edit: this one:
https://forums.freebsd.org/threads/scripted-network-management-with-network-sh.62013/post-357776


----------

