Skip to content

Instantly share code, notes, and snippets.

@jyxjjj
Created August 20, 2025 05:06
Show Gist options
  • Save jyxjjj/30bb1177d94e8ffebb8cec5f02c2a9f9 to your computer and use it in GitHub Desktop.
Save jyxjjj/30bb1177d94e8ffebb8cec5f02c2a9f9 to your computer and use it in GitHub Desktop.
FirewallD randomizing outbound IPv6 source IP selection
<?xml version="1.0" encoding="utf-8"?>
<direct>
<!-- probability: P(i) = 1 / (N - (i - 1)) -->
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0625 -j SNAT --to-source 2::::::0</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0667 -j SNAT --to-source 2::::::1</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0714 -j SNAT --to-source 2::::::2</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0769 -j SNAT --to-source 2::::::3</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0833 -j SNAT --to-source 2::::::4</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.0909 -j SNAT --to-source 2::::::5</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.1000 -j SNAT --to-source 2::::::6</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.1111 -j SNAT --to-source 2::::::7</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.1250 -j SNAT --to-source 2::::::8</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.1429 -j SNAT --to-source 2::::::9</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.1667 -j SNAT --to-source 2::::::a</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.2000 -j SNAT --to-source 2::::::b</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.2500 -j SNAT --to-source 2::::::c</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.3333 -j SNAT --to-source 2::::::d</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 0.5000 -j SNAT --to-source 2::::::e</rule>
<rule ipv="ipv6" table="nat" chain="POSTROUTING" priority="0">-m statistic --mode random --probability 1.0000 -j SNAT --to-source 2::::::f</rule>
</direct>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment