Single Blog

  • Home
  • MikroTik Hairpin NAT

MikroTik Hairpin NAT

exabytes 24 marca 2022 0 Comments

[fusion_builder_container hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” hundred_percent_height_center_content=”yes” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” border_size=”” border_color=”” border_style=”solid”][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” border_radius=”” box_shadow=”no” dimension_box_shadow=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”” margin_bottom=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”no”][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Załóżmy, że w sieci domowej (firmowej) chcemy postawić serwer www na wewnętrznym adresie IP i mieć do niego dostęp od strony internetu ale także w sieci lokalnej.

[/fusion_text][/fusion_builder_column][fusion_builder_column type=”2_3″ layout=”2_3″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” border_radius=”” box_shadow=”no” dimension_box_shadow=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”” margin_bottom=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”no”][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Adresacja naszej sieci wewnętrznej to 192.168.0.0/24 czyli adresy od 192.168.0.1 – 192.168.0.254

adres IP naszego routera (bramy) 192.168.0.1

adres IP naszego komputera 192.168.0.2

adres IP naszego serwera www 192.168.0.3   port 80 (czyli nie szyfrowany protokół http)

adres IP zewnętrzny 1.1.1.1

[/fusion_text][/fusion_builder_column][fusion_builder_column type=”1_3″ layout=”1_3″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” border_radius=”” box_shadow=”no” dimension_box_shadow=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”” margin_bottom=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”no”][fusion_imageframe image_id=”12222|full” max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”none” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]https://www.exabytes.pl/wp-content/uploads/2018/03/mikrotik-hairpin-nat-1.png[/fusion_imageframe][/fusion_builder_column][fusion_builder_column type=”1_1″ layout=”1_1″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” border_radius=”” box_shadow=”no” dimension_box_shadow=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”” margin_bottom=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”no”][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Pierwsze przekierowanie w naszym routerze robimy w zakładce  IP > Firewall > NAT (dostęp do serwera z zewnątrz)

/ip firewall nat
add action=dst-nat chain=dstnat comment=”serwer www” dst-address= 1.1.1.1 dst-port=80 in-interface=WAN protocol=tcp to-addresses= 192.168.0.3 to-ports=80

Wpis musi się znaleźć powyżej wpisu dotyczącego masquerade

W tym momencie nasza strona będzie już dostępna w internecie pod dowolną wykupioną i przekierowaną domeną np: www.exabytes.pl

Nasze komputery z sieci lokalnej nie będą miały dostępu do naszej strony www.exabytes.pl, mimo odpytania serwera DNS który zwróci nam adres 1.1.1.1 bo na taki mamy przekierowaną domenę, nasz router nie wskaże naszego serwera jako docelowego i otrzymamy w przeglądarce błąd strona nie istnieje.

[/fusion_text][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

I tu z pomocą przychodzi nam Hairpin NAT

Te wpisy dodajemy z kolei po wpisie dotyczącym masquerade czyli na samym końcu naszej tabeli NAT

/ip firewall nat
add action=masquerade chain=srcnat comment=”Hairpin Nat” dst-address= !192.168.0.1 src-address=192.168.0.0/24
add action=dst-nat chain=dstnat comment=”serwer www” dst-address= !192.168.0.1 dst-address-type=local dst-port=80 protocol=tcp to-addresses=192.168.0.3 to-ports=80

W tym momencie powinniśmy bez problemu otworzyć stronę w sieci lokalnej pochodzącej z naszego serwera.

[/fusion_text][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Do czego możemy jeszcze wykorzystać Hairpin NAT

Jeżeli mamy w naszej sieci wewnętrznej np: rejestratory kamer (monitoring),

przekierowujemy port np 3337 według pierwszej reguły  – nasz rejestrator będzie dostępny pod adresem 1.1.1.1:3337

Ustawiając w ten sposób nasz program, będziemy mieli dostęp z zewnątrz, ale nie z sieci lokalnej (wewnętrznej).

Z kolei jak dodamy reguły Hairpin NAT dotyczące rejestratora nie będziemy musieli zmieniać adresacji IP do podglądu z zewnątrz firmy jak i sieci wewnętrznej.

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]