Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a question.

I have a ubuntu server(GW0). It has 2 interfaces.


eth0: 10.20.26.10 - connected to router

eth1: 192.168.1.20 - connected to switch


eth0: 10.20.26.0/24, gw: 10.20.26.1

eth1: 192.168.1.0/24, gw: 192.168.1.254 (192.168.1.254 server placed in my network it has internet access)


I want to use this server(GW0) as my gateway for my 192.168.1.0/24 network to access 10.20.x.x subnets via 10.20.26.1 router and internet access from 192.168.1.254.

What i did.

  1. echo 1 > /proc/sys/net/ipv4/ip_forward
  2. route add default gw 192.168.1.254

if i do like this internet works fine from my network, but can't access 10.20.x.x.

update 1: if i use default gw 10.20.26.1.

  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  iptables -A FORWARD -i eth0 -j ACCEPT

i can access 10.20.x.x, but not internet.

Than i try to use iproute.

echo 1 corp >> /etc/iproute2/rt_tables
ip route add default via 10.20.26.1 dev eth0 table corp
ip rule add from 10.20.0.0/16 table corp

How to make to this work to reach 10.20.x.x and internet. Thanks beforehand.

share|improve this question
add comment

1 Answer

you need a specific route to cover the /16

policy based routing is unnecessary.

ip route add default via 192.168.1.254

ip route add 10.20.0.0/16 via 10.20.26.1

share|improve this answer
    
i added ip route add default via 192.168.1.254 and ip route add 10.20.0.0/16 via 10.20.26.1. But still my network can't reach 10.20.x.x. Can you explain step by step pls. Thanks –  sarik_in Mar 3 '13 at 7:41
    
The machines you want to reach need to know how to get traffic back to you. –  David Schwartz Mar 3 '13 at 8:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.