Linux bridge SNAT with ebtables

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












4















I was reading the following code (dot1x bridge bypass):
https://github.com/mubix/8021xbridge/blob/master/scripts/trans_bridge.prepop



A quick description, we have 2 interfaces, the first is connected to a switch ($SWINT) and the other to our target host. The goal is to
interact with the rest of the network, while making it look like the traffic is generated by the target host.



From the referenced code, what I am trying to figure out is why both of the below commands are needed:



# use ebtables to source NAT the $COMPMAC for traffic leaving the device from the bridge mac address
(A)ebtables -t nat -A POSTROUTING -s $SWMAC -o $SWINT -j snat --to-src $COMPMAC
(B)ebtables -t nat -A POSTROUTING -s $SWMAC -o $BRINT -j snat --to-src $COMPMAC


I don't get why it's needed to SNAT the POSTROUTING traffic of $BRINT. Since our goal is to avoid transmitting any frames towards switch side interface with source MAC different than the target host, shouldn't the first ebtables rule be suffice?



Or in other words, isn't $SWINT (switch side interface) the only way any frames are getting to the switch? Based on the diagram below, the rule (B) looks redundant since we only care for frames going towards eth0 (SWINT), and we already apply SNAT to eth0.



Some good resources I found on bridges (but still haven't answered my question) are:



Understanding Linux Network Internals



Anatomy of Linux Bridge



ebtables with Linux Bridge



https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359
https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359










share|improve this question




























    4















    I was reading the following code (dot1x bridge bypass):
    https://github.com/mubix/8021xbridge/blob/master/scripts/trans_bridge.prepop



    A quick description, we have 2 interfaces, the first is connected to a switch ($SWINT) and the other to our target host. The goal is to
    interact with the rest of the network, while making it look like the traffic is generated by the target host.



    From the referenced code, what I am trying to figure out is why both of the below commands are needed:



    # use ebtables to source NAT the $COMPMAC for traffic leaving the device from the bridge mac address
    (A)ebtables -t nat -A POSTROUTING -s $SWMAC -o $SWINT -j snat --to-src $COMPMAC
    (B)ebtables -t nat -A POSTROUTING -s $SWMAC -o $BRINT -j snat --to-src $COMPMAC


    I don't get why it's needed to SNAT the POSTROUTING traffic of $BRINT. Since our goal is to avoid transmitting any frames towards switch side interface with source MAC different than the target host, shouldn't the first ebtables rule be suffice?



    Or in other words, isn't $SWINT (switch side interface) the only way any frames are getting to the switch? Based on the diagram below, the rule (B) looks redundant since we only care for frames going towards eth0 (SWINT), and we already apply SNAT to eth0.



    Some good resources I found on bridges (but still haven't answered my question) are:



    Understanding Linux Network Internals



    Anatomy of Linux Bridge



    ebtables with Linux Bridge



    https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359
    https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359










    share|improve this question


























      4












      4








      4








      I was reading the following code (dot1x bridge bypass):
      https://github.com/mubix/8021xbridge/blob/master/scripts/trans_bridge.prepop



      A quick description, we have 2 interfaces, the first is connected to a switch ($SWINT) and the other to our target host. The goal is to
      interact with the rest of the network, while making it look like the traffic is generated by the target host.



      From the referenced code, what I am trying to figure out is why both of the below commands are needed:



      # use ebtables to source NAT the $COMPMAC for traffic leaving the device from the bridge mac address
      (A)ebtables -t nat -A POSTROUTING -s $SWMAC -o $SWINT -j snat --to-src $COMPMAC
      (B)ebtables -t nat -A POSTROUTING -s $SWMAC -o $BRINT -j snat --to-src $COMPMAC


      I don't get why it's needed to SNAT the POSTROUTING traffic of $BRINT. Since our goal is to avoid transmitting any frames towards switch side interface with source MAC different than the target host, shouldn't the first ebtables rule be suffice?



      Or in other words, isn't $SWINT (switch side interface) the only way any frames are getting to the switch? Based on the diagram below, the rule (B) looks redundant since we only care for frames going towards eth0 (SWINT), and we already apply SNAT to eth0.



      Some good resources I found on bridges (but still haven't answered my question) are:



      Understanding Linux Network Internals



      Anatomy of Linux Bridge



      ebtables with Linux Bridge



      https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359
      https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359










      share|improve this question
















      I was reading the following code (dot1x bridge bypass):
      https://github.com/mubix/8021xbridge/blob/master/scripts/trans_bridge.prepop



      A quick description, we have 2 interfaces, the first is connected to a switch ($SWINT) and the other to our target host. The goal is to
      interact with the rest of the network, while making it look like the traffic is generated by the target host.



      From the referenced code, what I am trying to figure out is why both of the below commands are needed:



      # use ebtables to source NAT the $COMPMAC for traffic leaving the device from the bridge mac address
      (A)ebtables -t nat -A POSTROUTING -s $SWMAC -o $SWINT -j snat --to-src $COMPMAC
      (B)ebtables -t nat -A POSTROUTING -s $SWMAC -o $BRINT -j snat --to-src $COMPMAC


      I don't get why it's needed to SNAT the POSTROUTING traffic of $BRINT. Since our goal is to avoid transmitting any frames towards switch side interface with source MAC different than the target host, shouldn't the first ebtables rule be suffice?



      Or in other words, isn't $SWINT (switch side interface) the only way any frames are getting to the switch? Based on the diagram below, the rule (B) looks redundant since we only care for frames going towards eth0 (SWINT), and we already apply SNAT to eth0.



      Some good resources I found on bridges (but still haven't answered my question) are:



      Understanding Linux Network Internals



      Anatomy of Linux Bridge



      ebtables with Linux Bridge



      https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359
      https://doc.lagout.org/operating%20system%20/linux/Understanding%20Linux%20Network%20Internals.pdf Page:359







      firewall bridge






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago







      gip

















      asked Jan 13 at 20:21









      gipgip

      665




      665




















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494302%2flinux-bridge-snat-with-ebtables%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494302%2flinux-bridge-snat-with-ebtables%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)