I have a Linux script that allows me to route some traffic through a VPN interface, and other traffic (from different IP) through another interface. This is my script:
echo "ip route del default via 192.168.120.10 dev ppp0;" >> /tmp/firewallscript.sh
echo "ip route add default via 192.168.1.254 dev eth0;" >> /tmp/firewallscript.sh
echo "ip route add table 55 default via 192.168.120.10 dev ppp0;" >> /tmp/firewallscript.sh
echo "iptables -t mangle -I PREROUTING 1 -s 192.168.1.40 -j MARK --set-mark 55;" >> /tmp/firewallscript.sh
echo "iptables -t mangle -I PREROUTING 1 -s 192.168.1.41 -j MARK --set-mark 55;" >> /tmp/firewallscript.sh
echo "iptables -t mangle -I PREROUTING 1 -s 192.168.1.42 -j MARK --set-mark 55;" >> /tmp/firewallscript.sh
echo "ip rule add fwmark 55 table 55;" >> /tmp/firewallscript.sh
Because my VPN's IP changes a lot, I would like to 'parametrize' it. So instead of write this line code:
echo "ip route del default via 192.168.120.10 dev ppp0;" >> /tmp/firewallscript.sh
I need to write something like:
echo "ip route del default via @MyVariableIP dev ppp0;" >> /tmp/firewallscript.sh
In which @MyVariableIP is ppp0's IP address. So my questions are:
- How can I get interface IP address using bash, knowing that the interface is ppp0?
- How to modify the previous script?
Thanks
Put this script before yours and replace @MyVariableIP with $ip_of_ppp0