Yes, absolutely! On Linux, you can definitely set up virtual interfaces or IP aliases, and then use Network Address Translation (NAT), specifically Source NAT (SNAT) or Masquerading, to map each of those internal IPs to a different external IP address.
This is a common setup for scenarios like:
Server hosting multiple websites/services with different public IPs.
Providing dedicated external IPs to different applications or virtual machines.
Testing MPTCP with multiple distinct source IPs that you control.
How it Works:
Internal IPs: You assign a set of private or internal IP addresses to virtual interfaces or as secondary IP addresses (aliases) on your main interface (wlan0 in your case).
External IPs: You need to have a pool of public, routable IP addresses available to you. These IPs must be properly configured on your wlan0 interface or be routed to your machine by your network provider/gateway.
iptables (or nftables) for NAT: You use firewall rules (iptables) to intercept outgoing packets from your internal IPs and change their source IP address to one of your external IPs before they leave the wlan0 interface.
Example Scenario:
Let's say:
Your physical interface:wlan0
Your "internal" IPs you want to assign:
192.168.100.1
192.168.100.2
192.168.100.3
Your available "external" IPs (assigned to wlan0 or provided by your ISP):
203.0.113.10
203.0.113.11
203.0.113.12
Steps using iptables:
1. Assign the Internal IPs (as IP Aliases on wlan0)
bash
sudo ip addr add 192.168.100.1/24 dev wlan0
sudo ip addr add 192.168.100.2/24 dev wlan0
sudo ip addr add 192.168.100.3/24 dev wlan0
(Note: This makes 192.168.100.0/24 the subnet for these aliases. Adjust subnet mask if needed).
2. Ensure External IPs are Configured on wlan0
You need to have these IPs active on wlan0. This is the crucial part – your network environment must provide these IPs to your machine.
bash
# Example: if your ISP provided them to you directly on wlan0
sudo ip addr add 203.0.113.10/32 dev wlan0
sudo ip addr add 203.0.113.11/32 dev wlan0
sudo ip addr add 203.0.113.12/32 dev wlan0
(Using /32 for host IPs is common for NAT targets).
3. Configure iptables for Source NAT (SNAT)
You'll add rules to the nat table, specifically in the POSTROUTING chain.
-t nat: Specifies that we are working with the NAT table.
-A POSTROUTING: Appends the rule to the POSTROUTING chain, which is processed just before packets are sent out of the network interface.
-s <source_ip>: Matches packets originating from this specific source IP.
-o wlan0: Matches packets exiting through the wlan0 interface.
-j SNAT --to-source <external_ip>: The target action. SNAT (Source NAT) changes the source IP address to the specified external IP.
Combining with MPTCP:
If you want to use this setup with MPTCP, it gets a bit more intricate:
MPTCP Subflows: MPTCP will typically try to use the IP addresses directly configured on your interfaces as source IPs for its subflows.
NAT and MPTCP: When iptables performs SNAT, it's changing the source IP after MPTCP has potentially decided on the source IP for a subflow. This can sometimes cause issues if the NATed IP doesn't match what the MPTCP peer expects or if routing gets confused.
Best Practice for MPTCP: For MPTCP to truly leverage multiple distinct public source IPs, it's often cleaner if those public IPs are themselves assigned to your machine (e.g., on different interfaces or as aliases if the kernel supports MPTCP with aliases correctly) and then MPTCP uses those direct IPs for its subflows. This bypasses the need for SNAT on your end for the MPTCP subflows themselves.
However, if your goal is simply to make traffic from different internal IPs appear as if it's coming from different external IPs, the iptables SNAT method is exactly what you need.