Skip to content Prejsť na obsah


How to redirect traffic to another machine in Linux Ako presmerovať prevádzku na iný stroj v Linuxe

LinuxWeb Design & Dev

If you have ever handled the migration of a web service or a website from one server to another you know how crazy the experience can be. Ak ste niekedy riešili sťahovanie webové služby alebo webovej stránky z jedného servera na iný viete, ako blázon skúsenosť môže byť. However, if you break the process up into clear steps and run constant checks you can make the experience a little easier on yourself. Avšak, ak porušíte procese až do jasné kroky a spustiť stálu kontrolu môžete vykonať zážitok trochu ľahšie na seba. One of the problems that you might run into towards the end of the migration is the period when you have the website running well on the new location but need to wait for the domain name to be forwarded to the new server. Jedným z problémov, na ktoré môžete naraziť na konci migrácie je obdobie, keď máte webové stránky bežia aj na novom mieste, ale je potrebné počkať na doménové meno, ktoré majú byť odovzdané na nový server. you can either shut down your service till the domain is done forwarding, or you can setup your first server to forward all its traffic to the new server. môžete buď vypnúť službu až do domény sa vykonáva presmerovanie, alebo si môžete nastaviť svoj prvý server, aby odovzdal všetky svoje prevádzky na nový server. Let's take a look at how you can do that on a Linux machine using IPTables. Poďme sa pozrieť, ako môžete urobiť, že na stroji Linuxe pomocou iptables.

In case you didn't already know, IPtables is a software firewall that ships with most distributions of Linux. V prípade, že ste už nevedeli, iptables firewall je softvér, ktorý je dodávaný sa väčšine distribúcií Linuxu. It is an extremely useful software and can be used for a lot more than just as a firewall. Je to veľmi užitočný softvér a môže byť použitý pre oveľa viac než len ako firewall. In this exercise we will configure IPTables on a Linux server to redirect all the traffic coming on port 80, (which is the default web server port), to a server with the IP 122.164.34.240 . V tomto cvičení sa budeme konfigurovať iptables na serveri Linux presmerovať všetky prichádzajúce prevádzku na porte 80 (čo je predvolený webový server port), na server s IP 122.164.34.240. The first step is to set your Linux box to allow this kind of forwarding to take place. Prvým krokom je nastavenie Linux box, aby tento spôsob odovzdania sa uskutoční. Open a terminal window, log in as root user and run the following command: Otvorte okno terminálu, prihláste sa ako užívateľ root a zadajte nasledujúci príkaz:

# echo 1 >/proc/sys/net/ipv4/ip_forward # Echo 1> / proc/sys/net/ipv4/ip_forward

The next step is to tell IPTables to redirect the traffic to the new server: Ďalším krokom je povedať iptables presmerovať prevádzku na nový server:

# iptables -t nat -D PREROUTING -p tcp –dport 80 -j DNAT –to-destination 122.164.34.240 # Iptables-t nat-D POSTROUTING-p tcp-dport 80-j DNAT-k-cieľ 122.164.34.240

Here's where the IPTables magic happens. Tu je miesto, kde mágia iptables stane. With the third and final step we tell IPTables to rewrite the origin of connections to the new server's port 80 to appear to come from the old server. S tretím a posledným krokom povieme iptables prepísať pôvodu pripojenie k novému serveru portu 80 až zdá, pochádzajú zo starého servera.

# iptables -t nat -D POSTROUTING -p tcp -d 122.164.34.240 –dport 80 -j MASQUERADE # Iptables-t nat-D POSTROUTING-p tcp-d 122.164.34.240-dport 80-j Masquerade

The final step is required because if we don't tell the web server of the new server that the connections are coming from the client machines, it would think that they are originating from the old server. Posledným krokom je potrebné, pretože ak nebudeme povedať webovému serveru nového servera, pripojenie sú posielané z klientských počítačov, by to myslím, že oni sú pôvodom z pôvodného servera.

Posted in Publikované v Linux Linux , , Web Design & Dev Web Design & Dev . .

Related Posts: Súvisiace zmeny:

How to set the date on your Linux machine Ako nastaviť dátum na počítači Linux
How to monitor your Linux machine with netstat Ako sledovať váš počítač s Linuxom netstat
How to see a detailed history of the commands run in Linux Ako vidieť podrobnú históriu príkazov spustiť v Linuxe
Walkthrough: Time Machine for OS X 10.5 Leopard Návod: Time Machine pre OS X 10.5 Leopard
An introduction to the sudo command and configuration file Úvod do príkaz sudo a konfiguračný súbor

2 Responses 2 Citlivosť

Stay in touch with the conversation, subscribe to the Zostať v kontakte s konverzácia, prihláste sa RSS feed for comments on this post RSS kanál pre komentáre k tomuto príspevku . .

  1. cosco says COSCO hovorí

    Thanks, I googled a lot before finding your post, without success. Vďaka, veľa som googled pred záver svojho príspevku, ale bez úspechu.
    That does exactly what I want. , Ktorý robí presne to, čo chcem.
    However, there is a typo : Avšak, tam je preklep:
    “iptables -t nat -D PREROUTING” should read “iptables -t nat -A PREROUTING” "Iptables-t nat-D POSTROUTING" by mal znieť "iptables-t nat-A prerouting"

  2. David Madl David Madl says hovorí

    Many thanks, works perfectly well with -A instead of -D (which is for deleting the rules). Mnohokrát děkuji, funguje veľmi dobre s-miesto-D (čo je pre mazanie pravidlá).



Some HTML is OK Niektoré HTML je v poriadku

or, reply to this post via alebo odpovede na tento príspevok prostredníctvom trackback Trackback . .