If by "use" you mean receiving requests and serving sites, you need to configure Apache (or your webserver) to do that with Listen vpnIP:80
and Listen vpnIP:443
. So it won't work on the other IPs.
Additionally using iptables, you can DROP port 80 and 443 for eth0 and only allow on the VPN interface (I used tun0 below) with;
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j DROP
-A INPUT -i eth0 -p tcp -m tcp --dport 443 -j DROP
-A INPUT -i tun0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i tun0 -p tcp -m tcp --dport 443 -j ACCEPT
If by "use" you mean outgoing connection (surfing the web), one way is to install a proxy (like squid) on the server (or somewhere within the VPN) and configure the proxy to send all traffic trhough VPN default gateway. You can use iptables NAT table to redirect port 80 and 443 to the proxy port (3128 for squid) using:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.1.2:3128
iptables -t nat -A PREROUTING -i tun0 -p tcp --dport 80 -j REDIRECT --to-port 3128
Assuming:
tun0 = vpn interface
192.168.1.2 = IP of your server on tun0 (vpn)
And do the same for port 443.
Needs some testing and adjustments probably but this is the general behavior if going this way.
route
is deprecated on linux, you meanip route add [host connecting to] via [your gateway address]
– BatchyX – 2013-03-16T20:05:37.733Well, route works as well. The above was literally copypasted from my terminal. – Viljo Viitanen – 2013-03-16T21:50:18.990