Jump to content

Recommended Posts

Posted

Кто-то знает алгоритм трансляции адресов при использовании опции SNAT --persistent ?

 

Когда использовали опцию --same - все было понятно. Когда перешли на --persistent - старый алгоритм не подходит.

В итоге мне нужно зная ip отправителя и правило iptables - получить ip под которым выйдет пакет в свет.

 

Смотрел в исходниках. Я в Си - полный ноль. Не смог разобраться =((

Posted

Можно использовать -j NETMAP, там с алгоритмом всё предельно ясно.

NETMAP is a new implementation of the SNAT and DNAT targets where the host part of the IP address isn't changed. It provides a 1:1 NAT function for whole networks which isn't available in the standard SNAT and DNAT functions. For example, lets say we have a network containing 254 hosts using private IP addresses (a /24 network), and we just got a new /24 network of public IP's. Instead of walking around and changing the IP of each and every one of the hosts, we would be able to simply use the NETMAP target like -j NETMAP -to 10.5.6.0/24 and voila, all the hosts are seen as 10.5.6.x when they leave the firewall. For example, 192.168.0.26 would become 10.5.6.26.
Posted

Сам выбор:

        /* Hashing source and destination IPs gives a fairly even
         * spread in practice (if there are a small number of IPs
         * involved, there usually aren't that many connections
         * anyway).  The consistency means that servers see the same
         * client coming from the same IP (some Internet Banking sites
         * like this), even across reboots. */
        minip = ntohl(range->min_ip);
        maxip = ntohl(range->max_ip);
        j = jhash_2words((__force u32)tuple->src.u3.ip,
                         range->flags & IP_NAT_RANGE_PERSISTENT ?
                                0 : (__force u32)tuple->dst.u3.ip ^ zone, 0);
        j = ((u64)j * (maxip - minip + 1)) >> 32;
        *var_ipp = htonl(minip + j);

 

Тоесть алгоритм то несложный , но узнать под каким ip уйдет можно только выполнив вышеприведенный кусок кода(просто так не прикинуть - хеш всеже). Как вариант - написать мелкую утилитку для рассчета , но я так понимаю не совсем устроит?

Posted
у меня трансляция не 1:1

NETMAP не требует трансляции именно 1:1. Зато он строго регламентирует, в какой именно IP из пула будет транслирован src-адрес клиента. То, что вам нужно.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...
На сайте используются файлы cookie и сервисы аналитики для корректной работы форума и улучшения качества обслуживания. Продолжая использовать сайт, вы соглашаетесь с использованием файлов cookie и с Политикой конфиденциальности.