1

This is slightly confusing for me. I have 1 VPS server, which has 2 IP addresses (WAN) What i want to do is NAT each ip to route traffic to certain peers. What i have done is I made 2 wg interfaces (wg0 & wg1) Each of them has 1 peer, 2 computers at home. Something like:


                                  +------------+        
                                  |            |       
        +-------------------------+ Home PC 1  +------- Wan IP: 195.201.143.231 (When checked trough What is My IP)
        |                         |            |        WG: 10.9.0.2
+------+-----------------+        +------------+                         
|     wg0 - 10.9.0.1/24  |                                            
|                        |                                             
+ eth0   195.201.143.231 |
| eht0:1 195.201.143.232 |                                          
|                        |                                             
|     wg1 - 10.8.0.1/24  |                                            
+------+-----------------+        +------------+                           
       |                          |            |                          
       +--------------------------+ Home PC  2 +------- Wan IP: 195.201.143.232 (When checked trough What is My IP)
                                  |            |        WG:     10.8.0.2
                                  +------------+       

Currently it works quite like this no matter what i try:

                                  +------------+        
                                  |            |       
        +-------------------------+ Home PC 1  +------- Wan IP: 195.201.143.231 (When checked trough What is My IP)
        |                         |            |        WG: 10.9.0.2
+------+-----------------+        +------------+                         
|     wg0 - 10.9.0.1/24  |                                            
|                        |                                             
+ eth0   195.201.143.231 |
| eht0:1 195.201.143.232 |                                          
|                        |                                             
|     wg1 - 10.8.0.1/24  |                                            
+------+-----------------+        +------------+                           
       |                          |            |                          
       +--------------------------+ Home PC  2 +------- Wan IP: 195.201.143.231 (When checked trough What is My IP)
                                  |            |        WG:     10.8.0.2
                                  +------------+       

Any ideas will be appreciated.

Sorry if I made some mistakes, my primary language is not English.

0

The only diffrerence I see in the pictures is the public IP of Home2 - so you want packages sent out to the world to have a different source address?

Try this: iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -o eth0 -j SNAT --to 195.201.143.232

6
  • I have posted that rule as an extra my main target is to be able to split the outoging connections from wg0 to .231 and wg1 to .232, because some apps, when forwarded with iptables see the wrong IP address. when traffic goes out from wg1 is seen as .231 instead of .232. – Kumar Akhashar Feb 15 at 20:30
  • Also last time when i added SNAT, all incoming traffic wat listed as 10.8.0.1 instead of the real client ip. Lets say someone with ip 12.12.12.12 visits a webpage while using SNAT appears as 10.8.0.1. – Kumar Akhashar Feb 15 at 20:31
  • Just tried it and i get: iptables v1.8.4 (legacy): Can't use -i with POSTROUTING – Kumar Akhashar Feb 15 at 20:33
  • That sound like you are doing it for the wrong direction? Ok, I edited the command... – Virsacer Feb 15 at 20:38
  • Seems to be working right now, i will test it carefully and get back to you. Huge thanks!!!! – Kumar Akhashar Feb 15 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.