Yes, on Linux you can create a virtual interface where all traffic is mapped to an external IP address using Network Address Translation (NAT). This is commonly done using iptables for NAT rules and either dummy interfaces (for simple cases) or macvlan/ipvlan interfaces (for more advanced setups).
Here's how to do it step-by-step:
Simple Setup: Single Virtual Interface → Single External IP
All traffic from the virtual interface is mapped to your main external IP (e.g., your Wi-Fi/Cable modem IP).
1. Create a Virtual Interface
bash
# Create a dummy interface
sudo ip link add virt0 type dummy
sudo ip link set virt0 up
# Assign a private IP address to it
sudo ip addr add 192.168.100.100/24 dev virt0
2. Enable IP Forwarding
bash
sudo sysctl -w net.ipv4.ip_forward=1
3. Add NAT Rule (Masquerade Traffic)
bash
# Replace 'wlan0' with your physical interface (eth0, enp0s3, etc.)
sudo iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o wlan0 -j MASQUERADE
What this does: Any traffic from 192.168.100.0/24 (your virtual interface) will appear to come from your external IP when leaving via wlan0.
Map each IP on your virtual interface to a different external IP (requires multiple public IPs).
1. Assign Additional Public IPs to Your Physical Interface
bash
# Add extra IPs to wlan0 (replace 1.2.3.4/5 with your public IPs)
sudo ip addr add 1.2.3.4/24 dev wlan0
sudo ip addr add 1.2.3.5/24 dev wlan0
2. Create Virtual Interfaces
bash
# Create two dummy interfaces
sudo ip link add virt0 type dummy
sudo ip link add virt1 type dummy
sudo ip link set virt0 up
sudo ip link set virt1 up
# Assign private IPs to them
sudo ip addr add 192.168.100.10/32 dev virt0
sudo ip addr add 192.168.100.11/32 dev virt1