Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script that runs from cron every 15 minutes. The script is meant to ping my DNS server to update a dynamically changing IP. I want this script to ping through the wlan interface and not the eth0.

However, other processes should use eth0 as the primary interface to access the internet.

How do I do this for a specific process only without disturbing other processes? Is there a way to direct traffic through interface like directing stdout? like ls -al > /dev/tty2'. Can chroot help me in this by giving me a sandboxed environment?

share|improve this question
    
possible duplicate of Redirect traffic through vpn on an as needed basis –  Gilles Feb 26 '13 at 23:21

1 Answer 1

up vote 4 down vote accepted

The solution is to set the Netfilter packet mark which can be used by advanced routing. There is no way to match by process id, but Netfilter allows to match on process UID or GID. In this case it seems to be the easiest solution to create a new system user especially for this task.

iptables -A OUTPUT -m owner --uid-owner wlanping -j MARK --set-mark 42

Create a new routing table (forecewlan) in /etc/iproute2/rt_tables and chose the wlan gateway as default gateway:

ip route add default via $WLAN_GATEWAY

and force the use of this routing table for packets with this mark:

ip rule add fwmark 42 table forcewlan

Maybe you also have to copy this kind of entry from the main routing table:

192.168.0.0/24 dev wlan0  proto kernel  scope link  src 192.168.0.100
share|improve this answer

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.