1
I need to add an IP to my routing. I'm connected to a lab with Openvpn. My routing looks like this now;
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.178.1 0.0.0.0 UG 600 0 0 wlan0
192.168.178.0 0.0.0.0 255.255.255.0 U 600 0 0 wlan0
192.168.193.0 0.0.0.0 255.255.255.0 U 0 0 0 tap0
I need to add (example) IP 20.20.20.0/24 so I can visit webserver 20.20.20.8 via tap0. I can't get this to work. How do I set up the correct gateway and IP?
dont forget to make your script executable and always use full path for the commands in your scripts. Not 'route' but '/sbin/route' or wherever its placed in your server. use
whereis route
to find out the full path – Shirker – 2016-07-02T12:12:17.723Looked at it but it doesn't make sense to me. I've tried the commands like ip route add 20.20.20.0/24 via xx.xx.xx.xx but I can't get it to work – None – 2016-07-02T12:18:04.637
@BButter10 don't forget the
dev tap0
at the end of yourroute add
command. Are you getting an error or is it just silently failing? Update your question withtraceroute 20.20.20.8
output. – HashHazard – 2016-07-02T12:45:06.097Thanks Hollowproc. What I don't understand is that I have to add an IP via a gateway that does not exist. – None – 2016-07-02T13:00:03.693
ip route add 20.20.20.0/24 via (GATEWAY) dev tap0 – None – 2016-07-02T13:01:11.450
But what is my gateway? 0.0.0.0 ? – None – 2016-07-02T13:01:50.233
Do a
traceroute
to a host in the 192.168.193.0/24 range and see what the first IP it hits in that range is. – HashHazard – 2016-07-02T13:07:37.780traceroute to 192.168.193.1 (192.168.193.1), 30 hops max, 60 byte packets 1 kali (192.168.193.72) 2998.935 ms !H 2998.897 ms !H 2998.889 ms !H – None – 2016-07-02T13:49:30.537
It's my own IP? – None – 2016-07-02T13:49:41.020
Ok so
route add 20.20.20.0/24 via 192.168.193.72 dev tap0
.. sidenote if this is for OSCP or other, they have dedicated help that may be more familiar with this specific issue. – HashHazard – 2016-07-02T14:07:25.183Thank you @Hollowproc, it is for something like OSCP but support is not responding to my messages. I've posted in the forum, contacted the support email.....no response. I did what you said and now I have 20.20.20.0 with gateway KALI. Host is still unreachable. I guess I'll have to wait for a response. It has been over 30 hours though. – BButter10 – 2016-07-02T14:17:13.243
@BButter10 do they have an IRC Channel? That's usually a pretty good place for online help/troubleshooting. – HashHazard – 2016-07-02T14:18:35.110
They do not have an IRC channel like OSCP. I'll wait a few hours and hope I'll get a response. – BButter10 – 2016-07-02T14:30:39.557
if you are using one of common known Linux, like Debian or Centos, just try following command
VPN_GW=$(ip addr show | grep -B 2 tap0 | grep -oP '(?<=inet ).*?(?= peer)'); [ ! -z "$VPN_GW" ] && ip route add 20.20.20.0/24 via $VPN_GW dev tap0 || echo "ERROR: No IP address assigned to tap0 device"
It will look for IP address of tap0 and add the route, or return an error – Shirker – 2016-07-02T16:46:48.313sorry, my bad.. The GW IP should be IP of your OpenVPN server, which is in same subnet as IP of your tap0. More likely its 192.168.193.1. So
ip route add 20.20.20.0/24 via 192.168.193.1 dev tap0
should work I guess. Also edited my answer – Shirker – 2016-07-02T20:23:26.707Thanks @Shirker, this is what I tried in the first place. It has not worked. This is what's strange to me. It should work? – BButter10 – 2016-07-03T05:33:20.750
It may not work if you dont have NAT enabled on your OpnVPN server. Something like
-A POSTROUTING -s 192.168.193.0/24 -o eth0 -j SNAT --to-source <external IP of OpenVPN server>
. As well allowing rule-A INPUT -i tap0 -j ACCEPT
– Shirker – 2016-07-04T06:01:13.660as well make sure ip_forward is enabled on your OpenVPN server.
echo 1 > /proc/sys/net/ipv4/ip_forward
andsed -i 's@net.ipv4.ip_forward = 0@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf
– Shirker – 2016-07-04T06:04:09.910you may try to check this article http://centos.mwzip.com/wiki/OpenVPN_setup for the basic OpenVPN setup on Centos
– Shirker – 2016-07-04T07:24:09.570