I am trying to setup a single-box network environment (on a fresh Linux VM running Debian 6.1) to test my application against a variety of network conditions.
The basic idea is:
- Create a VLAN, that has internet access.
- Apply
tc qdisc
on the vlan interface to simulate network packet loss/limited bandwidth etc. - Run my application and bind the connection against the VLAN interface.
However I am stuck in setting up the VLAN with internet access.
My steps are:
Set system flags
sysctl -w net.ipv4.ip_forward=1 sysctl -w net.ipv4.conf.all.rp_filter=0 sysctl -p
Create VLAN:
# add link and IP address ip link add name "ens4.201" link ens4 type vlan id 201 ip addr add 192.168.3.18/28 broadcast + dev "ens4.201" ip link set dev "ens4.201" up # config route table ip -4 route add "192.168.3.16/28" dev "ens4.201" table "201" ip -4 route add default via "192.168.3.17" table "201" ip -4 rule add from "192.168.3.18/28" table "201" ip -4 rule add oif "ens4" table "201" # config NAT in iptables iptables -t nat -A POSTROUTING -o ens4 -j MASQUERADE iptables -P FORWARD DROP iptables -A FORWARD -i ens4 -o ens4.201 -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -i ens4.201 -o ens4 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
Test:
# Has internet with interface ens4 curl --interface 'if!ens4' http://www.example.com <success> # But does not have internet with interface ens4.201 curl --interface 'if!ens4.201' http://www.example.com <timeout>
Could someone please shed some light on what I might have done wrong?
Linux VM
You'd need to provide the network configuration on the host side too. Typically the bridge on the host side isn't VLAN aware, unless it is specifically configured as one need to "expose" / "share" a trunk to the VMs. I have a feeling that you don't actually know what VLAN means / is for...