I have a apache webserver running on ubuntu 18.04 hosted on KVM This KVM is running on Linux Mint 20.1 host OS
The networking is setup using bridge in KVM
<network connections="1">
<name>host-bridge</name>
<uuid>some-uuid</uuid>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
I have firewall rules to pass traffic from the real network to the bridge
sudo iptables -I INPUT 1 -i lo -j ACCEPT
#Pass to KVM Bridge
sudo iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
sudo iptables -A FORWARD -i br0 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i virbr0 -o br0 -j ACCEPT
sudo iptables -I FORWARD -i br0 -o br0 -j ACCEPT
This is all working I am getting traffic to the host and routed to the kvm machine, external ips can connect and so can internal
Unfortunately I also have some custom html that changes behaviour through php based on whether the referrer is on the local lan or a remote ip
Since migrating to KVM from VmWare now everything comes up as sourced from the host ip address and this logic doesn't work
Is there a way to maintain the request ip address so i can keep the same behaviour?
I check ips in php with
function getUserIpAddress()
{
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
return $ip;
}
And I've tried outputing all the above and they all show up as the host linux mint machines local lan IP