Set IP address for virtual network interface

I have virtual interface tun0 connected to my vpn provider.
I used the following commands to set it up with openvpn (

ip route add default via $route_vpn_gateway dev $dev table 20
ip rule add from $ifconfig_local table 20
ip rule add to $route_vpn_gateway table 20
ip route flush cache

It gives me tun0 interface with IP address like 7.6.6.x/32 where x depends on the choosen vpn server. I want to change vpn server randomly so I don’t know the exact IP.

Also I have squid proxy. I want to set it up so that any proxied request will go to tun0 interface. Squid has tcp_outgoing_address. It all works together if I set current tun0 IP as tcp_outgoing_address, but when I switch vpn, IP address changes and squid stops working. The same time squid has no tcp_outgoing_interface setting.

Is it possible to have some predefined IP address for my tun0 interface? What is the right way to set it up?
Should I:

  • Change IP for the tun0 interface with the following command: ip addr change ... dev tun0?
  • Add new IP for the tun0 interface with ip addr add dev tun0 local ... peer ... and somehow make it default?
  • Make interface alias?
  • Create new dummy interface and make network bridge between dummy0 with any custom IP and tun0?


Leave a Reply