Hi again,
Did some tinkering with AI but seems like this solution doesn’t work. Atleast for me. The AI of course is a little outdated.
DHCP Client Configuration
First, set up two DHCP clients for your WAN interface:
/ip dhcp-client
add interface=ether1 use-peer-dns=yes add-default-route=yes
add interface=macvlan use-peer-dns=no add-default-route=no
The first client will be used for your primary connection, and the second for the specific computer.
IP Address Lists
Create two address lists to dynamically track your public IPs:
/ip firewall address-list
add list=public_ip1
add list=public_ip2
DHCP Script
Create a script to update the address lists when DHCP leases change:
/system script
add name=update_public_ips source={
:local dhcp1 [/ip dhcp-client get [find interface=ether1] address]
:local dhcp2 [/ip dhcp-client get [find interface=macvlan] address]
/ip firewall address-list set [find list=public_ip1] address=$dhcp1
/ip firewall address-list set [find list=public_ip2] address=$dhcp2
}
Add this script to DHCP lease events:
/system scheduler
add interval=1m name=update_public_ips on-event="/system script run update_public_ips"
NAT Configuration
Modify the NAT rules to use the address lists:
/ip firewall nat
add chain=srcnat out-interface=ether1 action=masquerade src-address=192.168.1.0/24 to-addresses=[/ip firewall address-list get [find list=public_ip1] address]
add chain=srcnat out-interface=macvlan action=src-nat src-address=<specific_computer_ip> to-addresses=[/ip firewall address-list get [find list=public_ip2] address]
Firewall Mangle Configuration
The mangle rules remain largely the same:
/ip firewall mangle
add chain=prerouting src-address=<specific_computer_ip> action=mark-connection new-connection-mark=second_ip_conn
add chain=prerouting connection-mark=second_ip_conn action=mark-routing new-routing-mark=second_ip_route
Routing Configuration
For the routing, we’ll use a script to update the route when the IP changes:
/system script
add name=update_second_ip_route source={
:local newIP [/ip firewall address-list get [find list=public_ip2] address]
/ip route set [find routing-mark=second_ip_route] gateway=$newIP
}
Initially set up the route:
/ip route
add dst-address=0.0.0.0/0 gateway=[/ip firewall address-list get [find list=public_ip2] address] routing-mark=second_ip_route
Add this script to run periodically:
/system scheduler
add interval=1m name=update_second_ip_route on-event="/system script run update_second_ip_route"
This setup will dynamically update your configuration as your public IPs change. Remember to replace <specific_computer_ip> with the actual IP of the computer that needs to use the second public IP.
Also, ensure your firewall rules are set up to allow the necessary traffic. This configuration assumes that both DHCP clients are on the same physical interface (ether1). If they’re on separate interfaces, you’ll need to adjust the interface names accordingly.