«

»

May 14

Static Routing in FreeBSD and Debian

Static Routing is achieved by manually adding routes to the routing table.In these systems, routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator. An entire network can be configured using static routes, but this type of configuration is not fault tolerant. When there is a change in the network or a failure occurs between two statically defined nodes, traffic will not be rerouted. This means that anything that wishes to take an affected path will either have to wait for the failure to be repaired or the static route to be updated by the administrator before restarting its journey. Most requests will time out (ultimately failing) before these repairs can be made. There are, however, times when static routes can improve the performance of a network. Some of these include stub networks and default routes

Static Routing Network Diagram

Fig: Static Routing Network Diagram

Configuration File for Router 1

#vim /etc/rc.conf

Add following information in your file.

hostname="router1"
ifconfig_bge0="inet 192.168.0.1/24"
ifconfig_nge0="inet 192.168.1.1/24"
gateway_enable="YES"
static_routes="net1"
route_net1="-net 192.168.2.0/24 192.168.0.2"

Configuration File for Router 2

#vim /etc/rc.conf

Add following information in your file.

hostname="router2"
ifconfig_bge0="inet 192.168.0.2/24"
ifconfig_nge0="inet 192.168.2.1/24"
gateway_enable="YES"
static_routes="net2"
route_net2="-net 192.168.1.0/24 192.168.0.1"

 

Now Reboot your both BSD routers.

# reboot

or,

# shutdown -r now

 

IP Configuration for Client PC

Set Static IP address to your each Clients

Client 1

IP address: 192.168.1.2/24
Gateway: 192.168.1.1/24

Client 2

IP address: 192.168.2.2/24
Gateway: 192.168.2.1/24

For Debian

eth0 is running in connected to ISP or dhcp server and eth1 is connected to Local LAN.
open file

/etc/network/interfaces

Setting for eth0
Code:

allow-hotplug eth0
iface eth0 inet dhcp

eth1 is running in static IP and setting is as below

Code:

auto eth1
iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

To enable routing you need to make a command
Code:

echo 1 > /proc/sys/net/ipv4/ip_forward

But with your configuration you also need a NAT. Because addresses 192.168.*** will not be routed to Internet, it is for private local networks. For enabling NAT, you need to add iptables rule:
Code:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

And FORWARD ACCEPT rules in filter table if you use it. By default, I think, all is accepted – you should change this if you have other connected clients you want to not be routed. These commands need to be executed after every boot, so write them on starting script, for example /etc/rc.local.

Leave a Reply