Sponsored Content
Top Forums UNIX for Dummies Questions & Answers iptables / ip route packet routing with multiple gateways Post 302924716 by Bishi on Wednesday 12th of November 2014 04:35:31 AM
Old 11-12-2014
Router iptables / ip route packet routing with multiple gateways

Hi all. Linux noob here.
I was hoping someone could help me with configuring some routing rules on my router, an Asus AC68.

The router is connected to two gateways, wan0_gateway and wan1_gateway.

I have rules set up in the router gui that will push all traffic from every IP other than my own to wan1_gateway.
This works well so far. What I would also like to do is push specific port ranges from my machine (192.168.1.2) onto the wan1_gateway also. For instance HTTP so that downloads will not affect performance of the wan0_gateway.

This is the script I was messing with so far.. I might be way off base here so any assistance is appreciated!

Code:
#!/bin/sh

ip route flush table 100
ip route del default table 100
ip rule del fwmark 1 table 100
ip route flush cache
iptables -t mangle -F PREROUTING

ip rule add fwmark 1 table 100 via $(nvram get wan1_gateway)
ip route flush cache

iptables -t mangle -A PREROUTING -m state --state NEW -p tcp --dport 80 -d 192.168.1.2 -j CONNMARK --set-mark 1
iptables -t mangle -A PREROUTING -m state --state NEW -p tcp --dport 443 -d 192.168.1.2 -j CONNMARK --set-mark 1
iptables -t mangle -A PREROUTING -m state --state NEW -p tcp --dport 8080 -d 192.168.1.2 -j CONNMARK --set-mark 1
iptables -t mangle -A PREROUTING -m state --state NEW -p tcp --dport 8443 -d 192.168.1.2 -j CONNMARK --set-mark 1

EDIT: Actually the following seems to be working... am I on the right track?
Code:
#!/bin/sh

ip route flush table 100
ip route del default table 100
ip rule del fwmark 1 table 100
ip route flush cache
iptables -t mangle -F PREROUTING

ip rule add fwmark 1 table 100 via $(nvram get wan1_gateway)
ip route flush cache

iptables -t mangle -A PREROUTING -p tcp -i br0 -m multiport --sports 80,20,21,443,8080,8443 -d 192.168.1.2 -j MARK --set-mark 1


Last edited by Bishi; 11-12-2014 at 07:41 AM..
 

10 More Discussions You Might Find Interesting

1. IP Networking

Adding an extra route to the ip routing table

In my college dorm, there is a file sharing network in the entire building. Problem is, there is only a manual for windows with the settings on how to connect... :mad: They say that you have to give the following command in cmd in windows: route add 172.16.71.0 mask 255.255.255.0... (2 Replies)
Discussion started by: Japie89
2 Replies

2. IP Networking

Software/tool to route an IP packet to proxy server and capture the Proxy reply as an

Hi, I am involved in a project on Debian. One of my requirement is to route an IP packet in my application to a proxy server and receive the reply from the proxy server as an IP packet. My application handles data at the IP frame level. My application creates an IP packet(with all the necessary... (0 Replies)
Discussion started by: Rajesh_BK
0 Replies

3. Solaris

how do i make a route entry permanent in the routing table on solaris 8?

how do I make sure that the entry in the routing table on Solaris 8 stay permanent after rebooting the server. For example route add 172.20.1.60 -netmask 255.255.255.0 172.20.255.253 Each time the server reboots the entry disappears when using the command netstat -nr (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

4. UNIX for Dummies Questions & Answers

Routing or Iptables connections by hostname or ip address

edit; I found a solution that works, see thread #3 https://www.unix.com/302417065-post3.html Hi there, I have a small dedicated server that has four ip addresses and by default my httpd sends request using the servers main ip for all outbound connections. I'm quite amateur at routing and... (4 Replies)
Discussion started by: mooofa
4 Replies

5. IP Networking

iptables specific ip routing via tun

hi guys! I was searching few days for a solution to my problem but haven't found one or I'm too dumb to understand. Here's what happened: I have a linux server used as a router. It has an eth0 and eth1 (local interface). I just installed openvpn (I need it only as a client), I configured it and... (0 Replies)
Discussion started by: shamora
0 Replies

6. IP Networking

Nat and packet limits with iptables

Hi all, I have a following situation: - I want certain source IPs to be natted to a different destination IP and Port. Following is how I am achieving it: /usr/local/sbin/iptables -t nat -A PREROUTING -p tcp -s 192.168.10.12 --dport 1500 -j DNAT --to-destination 192.168.10.20:2000 ... (3 Replies)
Discussion started by: ahmerin
3 Replies

7. AIX

Packet loss coming with big packet size ping

(5 Replies)
Discussion started by: Vishal_dba
5 Replies

8. IP Networking

iptables - MAC routing

Hi all, I have a solution where a system can have multiple physical interfaces but a single IP address. I am looking to insert a Squid proxy (that will also perform source NAT), but the return packets must go back to the correct interface. client network is 10.x.x.x network between the... (4 Replies)
Discussion started by: wabbit02
4 Replies

9. IP Networking

Packet going out of wrong interface due to OS automatically added cache route with lower metric

RHEL 7.0, IPV6 Scenario: I have routed specific network using network scripts. 1. "ip -6 route show" shows that route has been added. ( with metric 1024) 2. Ping of the specific IP through that route is successful. 3. Now after few days, for some reason, we see that cache route appears for... (3 Replies)
Discussion started by: msr1981
3 Replies

10. Solaris

A little complex: why my packet don't route?

I have solaris11 running in a kvm virtual machine,network works fine. I can configure it with dhcp or static. Of course packet forward in kvm machine is enabled The solaris11 machine can ping external network. I have setup a solaris10 zone inside the vm the solaris 10 zone use exclusive ip... (3 Replies)
Discussion started by: Linusolaradm1
3 Replies
routed(8)						      System Manager's Manual							 routed(8)

NAME
routed - Manages network routing tables SYNOPSIS
/usr/sbin/routed [-q | -s] [-dgt] [logfile] The routed daemon manages the network routing tables. FLAGS
Enables additional debugging information, such as bad packets received, to be logged. The routed daemon remains under control of the host that started it; therefore, an interrupt from the controlling host stops the routed process. Causes the routing daemon to run on a gateway host. This flag is used on internetwork routers to offer a route to the default destination. Inhibits the routed daemon from supplying Routing Information Protocol (RIP) data. The -q flag conflicts with the -s flag. Do not use the -q and -s flags together. Causes routed to supply RIP information even if it is not functioning as an Internet router. The -s flag conflicts with the -q flag. Do not use the -s and -q flags together. Causes all packets sent or received to be written to standard output. The routed daemon remains under control of the host that started it; therefore, an interrupt from the controlling host stops the routed process. DESCRIPTION
Use the routed daemon to manage the RIP only. Use gated to manage RIP plus other protocols. When routed starts, it finds any interfaces to directly connected hosts and networks that are configured into the system and marked as up. If multiple interfaces are present, routed assumes that the local host forwards packets between networks. The routed daemon transmits an RIP request packet on each interface (using a broadcast packet if the interface supports it) and then enters a loop, listening for RIP routing requests and response packets from other hosts. In addition, if routed is to supply RIP information to other hosts, it periodi- cally sends RIP update packets (containing copies of its routing tables) to any directly connected hosts and networks. When routed receives a RIP request packet and can supply RIP routing information, (the -s flag is set), it generates a reply (response packet) based on the information maintained in the kernel routing tables. The response packet contains a list of known routes, each marked with a hop count metric (the number of host-to-host connections in the route). The metric for each route is relative to the sending host. A metric of 16 or greater is considered to be infinite, or beyond reach. Updating Routing Tables If RIP processing is enabled, routed uses information contained in the RIP response and update packets from other hosts to update its rout- ing tables. However, routed uses the information in the RIP routing packet to update the tables only if at least one of the following con- ditions exists: No routing table entry exists for the destination network or host, and the metric associated with the route is finite (that is, the metric is less than 16). The source host of the packet is the router in the existing routing table entry. The routing table entry is old and the new information is about a route that is at least as efficient as the existing route. The new route is shorter than the one that is currently stored in the routing tables. (Note that routed determines relative route length by comparing the new metric with the one stored in the routing table.) When routed updates its internal routing tables, it generates an RIP update packet to all directly connected hosts and networks. Before updating the kernel routing tables, routed pauses for a brief period to allow any unstable conditions to stabilize. Besides processing incoming RIP packets, routed also checks the internal routing table entries periodically. The metric for any entry that has not been updated for 3 minutes is set to infinity and marked for deletion. The deletion is delayed for 60 seconds so that information about the invalidated route can be distributed throughout the network. A host that acts as an RIP router supplies its routing tables to all directly connected hosts and networks every 30 seconds. Using Gateways In addition to managing routes to directly connected hosts and networks, routed maintains information about distant and external gateways. At startup, routed reads the /etc/gateways file to learn about these gateways. The /etc/gateways file contains information about routes through distant and external gateways to hosts and networks that can be advertised through RIP. These routes are either static routes to specific destinations, or default routes that apply when a static route to a desti- nation is unspecified. Gateways that supply RIP routing information are marked active in the /etc/gateways file. The routed daemons distributes RIP routing information to active gateways; if no RIP routing information is received from the gateway for a period of time, routed deletes the associ- ated route from the routing tables. Gateways that do not exchange RIP routing information are marked passive in the /etc/gateways file. Routed maintains information about passive gateways indefinitely, and includes information about them in any RIP routing information transmitted. Gateways are identified as external to inform routed that another routing process installs the route. Information about external gateways is not maintained in the routing tables. Note that routes through external gateways must be to net- works only. If a logfile is specified, routed writes information about its actions to the specified log file. The log contains information about any changes to the routing tables and a history of recent route change messages sent and received that are related to changed routes. Signals The following signals have the specified effect when sent to the routed process using the kill(1) command: Displays internal routing tables. Broadcasts RIP packets with hop counts set to infinity. Essentially, these signals disable the local host as a router. On a sec- ond SIGHUP, SIGTERM, or SIGQUIT, routed terminates. FILES
Specifies the command path Routes through distant and external gateways Contains the network name database CAUTIONS
The gated and routed daemons should not both be run on the same host, as this may produce unpredictable results. Routes through external gateways must be to networks only. RELATED INFORMATION
Commands: route(8) Daemons: gated(8) delim off routed(8)
All times are GMT -4. The time now is 04:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy