I have linux box with one network interface and IP forwarding enabled. Let's say my IP address is 192.168.1.1
and MAC is 11:11:11:11:11:11
. When a packet which is not targeted for my host arrives, it gets routed by the kernel and the outgoing packet has source MAC address 11:11:11:11:11:11
, i.e. the MAC address of my host. I want to change this behavior and set a predefined source MAC address for all routed packets. Is it possible to achieve this with the standard networking tools available in Linux? If not, is it possible to implement this in user space with libraries like pcap?
Asked
Active
Viewed 3,347 times
1

rgerganov
- 111
- 1
- 4
-
2Why do you need this? – 030 Aug 21 '15 at 11:08
-
I am spoofing `host A` which sends packets to `host B`. `host B` has MAC filter that accepts only the MAC address of `host A`. When my machine is forwarding packets from A to B, the source MAC is changed and B is dropping them. – rgerganov Aug 21 '15 at 11:41
-
https://ebtables.netfilter.org/documentation/features.html : "MAC NAT: ability to alter the MAC Ethernet source and destination address. This can be useful in some very strange setups (a real-life example is available)." – poige Sep 05 '19 at 10:22
-
Routed packets have the frame stripped off, losing the MAC addresses in the frames. You can change the MAC address on the outbound interface to your predefined MAC address. Just be sure the low-order bit of the first octet is not set (multicast), and that the second-lowest-order bit i is set (locally defined). That does not require any libraries. – Ron Maupin Jun 07 '21 at 03:29
1 Answers
0
for packets marked with values 0x2 using iptables:
IP_ADDR_ETH0=`ifconfig eth0 | grep 'inet addr'| cut -d ':' -f 2 | cut -d ' ' -f 1 | tr -d '\n'`
iptables -t mangle -A OUTPUT -s ${IP_ADDR_ETH0} -p udp --match multiport --dports 319,320 -o eth0 -j MARK --set-mark 2
tc filter add dev eth0 parent 15:0 protocol ip prio 1 handle 0x2 fw action pedit ex munge eth src set ${MAC_ADDR_ETH1} pipe \
action pedit ex munge ip src set ${IP_ADDR_ETH1}

noel av
- 1
- 1