0

I have a virtualization server with one IP and 5 VM. To get internet access and ssh access in every VM I do this in

-------------/etc/network/interfaces-------

auto vmbr2 iface vmbr2 inet static address 192.168.0.254 netmask 255.255.255.0 bridge_ports none bridge_stp off bridge_fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s '192.168.0.0/24' -o vmbr0 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s '192.168.0.0/24' -o vmbr0 -j MASQUERADE post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 1022 -j DNAT --to 192.168.0.1:22 post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 1022 -j DNAT --to 192.168.0.1:22 

This is ok. Now I need set a different external proxy to every VM. For example: VM 192.168.0.1 used this proxy user:[email protected]:3218 to access the internet.

How can I do it? Is it possible using only iptables?

1 Answer 1

0

Please clarify - what do you want.

At first - iptables work only with packets. It can't set user and password for proxy.

But you can set redirect traffic from each VM(it's ipadress) to each own proxy server. I think iptables -t nat -A PREROUTING -i eth0 -s vm_ipaddress -p tcp —dport 80 -j DNAT —to proxy_ipaddress:port should help you.

2
  • thanks for your answer, I need to set one proxy per VM. I have external (another isp) proxies configured with squid. I would like to avoid implement this into each VM's OS. How can I do that using iptables or any service? Commented Aug 27, 2015 at 0:10
  • If you need separate proxy per VM, you can do it on host machine, as described below. May be you may want to write automation script like * read proxy from any source(file, database, etc) * read VM ip addresses from VM API. * create iptables rule: foreach vm_ip do: set_proxy proxy_ip:port Commented Aug 27, 2015 at 21:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.