Skip to content Skip to content


How to redirect traffic to another machine in Linux Kā novirzīt datplūsmu uz citu mašīnu un Linux

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. Ja Jums kādreiz ir jārīkojas migrāciju interneta pakalpojumu vai mājas lapā no viena servera uz citu, jūs zināt, kā traks pieredze var būt. However, if you break the process up into clear steps and run constant checks you can make the experience a little easier on yourself. Tomēr, ja jūs pārtraukums process līdz viennozīmīgi pasākumus un vadīt pastāvīgas pārbaudes varat veikt pieredzes nedaudz vieglāka par sevi. 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. Viena no problēmām, kas jums varētu uzskriet uz beigām migrāciju periodā, kad esat tīmekļa vietne darbojas arī uz jauno atrašanās vietu, bet jāgaida domēna nosaukumu jānosūta jaunu serveri. 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. Jūs varat vai nu jāslēdz pakalpojumu līdz domēns tiek darīts pāradresēšanu, vai arī varat setup savu pirmo serveris nosūta visus satiksmes jaunu serveri. Let's take a look at how you can do that on a Linux machine using IPTables. Let's to apskatīt, kā jūs varat darīt, ka Linux mašīnas, izmantojot iptables.

In case you didn't already know, IPtables is a software firewall that ships with most distributions of Linux. Ja Jūs vēl nebija zināms, iptables ir programmatūras ugunsmūri, lai kuģi ar lielāko daļu sadali Linux. It is an extremely useful software and can be used for a lot more than just as a firewall. Tas ir ļoti noderīgas programmatūras un to var izmantot daudz vairāk nekā tikai kā ugunsmūris. 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 . Jo šis pasākums mums būs jākonfigurē iptables uz Linux servera novirzīt visu automobilim, kas tuvojas no ostas 80, (kas ir noklusējuma Web servera portu), uz serveri ar 122.164.34.240 IP. The first step is to set your Linux box to allow this kind of forwarding to take place. Pirmais solis ir iestatīt Linux box, lai šāda veida nosūtīšanu notiks. Open a terminal window, log in as root user and run the following command: Atvērt termināla logu, pieteikties kā root lietotājam un palaist šādu komandu:

# 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: Nākamais solis ir pateikt iptables novirzīt datplūsmu uz jaunu serveri:

# iptables -t nat -D PREROUTING -p tcp –dport 80 -j DNAT –to-destination 122.164.34.240 # Iptables-t nat-A PREROUTING-p tcp-dport 80-j DNAT-to-galamērķi 122.164.34.240

Here's where the IPTables magic happens. Lūk, kur iptables burvju notiek. 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. Ar trešais un pēdējais solis mums pastāstīt iptables pārrakstīt izcelsmes savienojumi ar jaunā servera portu no 80 līdz, šķiet, nāk no vecā 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 maskēties

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. Pēdējais solis ir nepieciešams, jo, ja mums nav pateikt web serveri jaunu serveri ka savienojumi nāk no klientu mašīnām, tā varētu domāt, ka tās izcelsme ir no vecā servera.

Posted in Posted in Linux Linux , , Web Design & Dev Web Design & Dev . .

Get Simple Help tutorials just like this one in your email inbox every day - for free! Get Simple Palīdzība konsultācijas tāpat kā šo vienu savā e-pastā ik dienas - bez maksas! Just enter your email address below: Vienkārši ievadiet savu e-pasta adresi:

You can always opt out of this email subscription at any time. Jūs vienmēr varat atteikties no šīs e-pasta abonementu jebkurā laikā.

2 Responses 2 Atbildes

Stay in touch with the conversation, subscribe to the Uzturēt kontaktus ar sarunu, abonēt RSS feed for comments on this post RSS barību komentārus par šo ziņu . .

  1. cosco says COSCO saka

    Thanks, I googled a lot before finding your post, without success. Paldies, es googled daudz pirms secinājumu your post, bez panākumiem.
    That does exactly what I want. Tas tieši tas, ko vēlos.
    However, there is a typo : Tomēr ir typo:
    “iptables -t nat -D PREROUTING” should read “iptables -t nat -A PREROUTING” "Iptables-t nat-A PREROUTING" jālasa "iptables-t nat-A PREROUTING"

  2. David Madl David Madl says saka

    Many thanks, works perfectly well with -A instead of -D (which is for deleting the rules). Many thanks, strādā perfekti labi, nevis-D (kas ir svītrot noteikumus).



Some HTML is OK Daži HTML ir OK

or, reply to this post via vai, atbildot uz šo ziņu izmantojot trackback Trackback . .