2 Default Gateways
I'm busy setting up an Asterisk server and I've hit a slight hitch.
The setup requires that I have 2 network cards in the machine, one for the internal network and one for the SIP account.
IP Address: 192.168.3.100
Subnet Mask: 255.255.224.0
Gateway IP: 192.168.0.25 <- Internet Access
IP Address: 10.12.4.108
Subnet Mask: 255.255.255.248
Gateway IP: 10.12.4.105
And then under the SIP Peer details I set: host=10.8.0.5
Now I have to set the Gateway on Eth1 to 10.12.4.105 so that the SIP account can talk to 10.8.0.5 but then I do not have internet access on the Asterisk server because I have to clear the Gateway on Eth0.
Does anybody have any suggestions?
You should only ever have one default gateway as that is the address for the upstream router for Internet access. The default gateway, to my knowledge, is only used for Internet access. Remove the default gateway from Eth1. What it looks like you need to do is add some routing rules (sorry can't remember the syntax) to the Asterisk server. Letting the server know that there is a route to 10.8.x.x through 10.12.4.105. I think it should then work.
Thanks @tmcd35 - that sounds like exactly what I need to do!
So I'm still a bit stuck, could anybody give me a hint? :)
You probably want to set up some static routes on eth1 to reach your internal subnet(s).
Leave eth0 alone, default route to the internet is fine if that's what you need.
So you want eth1 to reach 10.8.0.5 via the internal gateway 10.12.4.105 right?
If you only need to reach 10.8.0.5 specifically you could try:
route add 10.8.0.5/32 gw 10.12.4.105 dev eth1
(if you need to see more than just 10.8.0.5 then you would put in the subnet scope)
If this completely breaks things just reboot the box as the route isn't persistent across reboots yet.
I use Centos at work, but I'm at home on Ubuntu, so this is from memory, so apologies for any errors. The networking in redhat/debian is quite different.
"route add" is temporary (I think), so you'll need to edit the routing scripts.
In Centos, the routing is done through script files in /etc/sysconfig/network-scripts/route-ethX where X is your card.
So, to build on tcmd35's suggestion, add this line to the file /etc/sysconfig/network-scripts/route-eth1
If you only have one address to worry about, you can specify a single address to be routed like this:
10.8.0.0/16 via 10.12.4.105
It's possible to specify routing on the more traditional address/netmask/gateway format (using three lines per entry), but the 'via' with bitmask is neater.
10.8.0.5/32 via 10.12.4.105
Here's a great little cheatsheet for netmask/bitmask conversions which everyone should bookmark. It also shows the binary masks so you get a good idea of how the address is split by the mask.
Restart your networking with the command: service network restart
Another possible gotcha, check the file /etc/sysconfig/network. This can have an entry called GATEWAY which (can) define the default gateway. However, routing in the roue-ethX script files will override any settings here. It can be confusing and it's one to watch.
Thanks guys, I'll give it a try now!