Replace a public IP by a private IP in a shell script [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












We have a shell script containing public ip.



i want to know if it's possible to use sed as a command that get the private ip of the server then replace the public ip










share|improve this question







New contributor




Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as unclear what you're asking by Rui F Ribeiro, mosvy, RalfFriedl, thrig, Romeo Ninov Nov 20 at 19:53


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















    up vote
    -1
    down vote

    favorite












    We have a shell script containing public ip.



    i want to know if it's possible to use sed as a command that get the private ip of the server then replace the public ip










    share|improve this question







    New contributor




    Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    closed as unclear what you're asking by Rui F Ribeiro, mosvy, RalfFriedl, thrig, Romeo Ninov Nov 20 at 19:53


    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      We have a shell script containing public ip.



      i want to know if it's possible to use sed as a command that get the private ip of the server then replace the public ip










      share|improve this question







      New contributor




      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      We have a shell script containing public ip.



      i want to know if it's possible to use sed as a command that get the private ip of the server then replace the public ip







      linux sed






      share|improve this question







      New contributor




      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 20 at 14:48









      Ali EL KANDOUSSI

      54




      54




      New contributor




      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Ali EL KANDOUSSI is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      closed as unclear what you're asking by Rui F Ribeiro, mosvy, RalfFriedl, thrig, Romeo Ninov Nov 20 at 19:53


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






      closed as unclear what you're asking by Rui F Ribeiro, mosvy, RalfFriedl, thrig, Romeo Ninov Nov 20 at 19:53


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          This will replace public IP 1.2.3.4 in place within the file my-script with private IP 192.168.6.9:



          $ sed -i'' -e 's/1.2.3.4/192.168.6.9/' my-script


          However, I don't see why you'd want to do that. If you have a machine with a public IP, it probably has a public domain name, so a better plan if the server can be seen via two different IPs is to override DNS using /etc/hosts.



          If the script uses domain name my.server.example.com instead of 1.2.3.4, then this /etc/hosts entry will override it:



          192.168.6.9 my.server.example.com


          That is to say, /etc/hosts doesn't have to be used just for simple host names. It can also override arbitrary domain names.



          Doing it this way means the same script will work from multiple locations without being changed.






          share|improve this answer



























            up vote
            0
            down vote













            I have done by below awk command



            awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt





            share|improve this answer




















            • Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
              – Jeff Schaller
              Nov 20 at 22:39

















            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            This will replace public IP 1.2.3.4 in place within the file my-script with private IP 192.168.6.9:



            $ sed -i'' -e 's/1.2.3.4/192.168.6.9/' my-script


            However, I don't see why you'd want to do that. If you have a machine with a public IP, it probably has a public domain name, so a better plan if the server can be seen via two different IPs is to override DNS using /etc/hosts.



            If the script uses domain name my.server.example.com instead of 1.2.3.4, then this /etc/hosts entry will override it:



            192.168.6.9 my.server.example.com


            That is to say, /etc/hosts doesn't have to be used just for simple host names. It can also override arbitrary domain names.



            Doing it this way means the same script will work from multiple locations without being changed.






            share|improve this answer
























              up vote
              0
              down vote













              This will replace public IP 1.2.3.4 in place within the file my-script with private IP 192.168.6.9:



              $ sed -i'' -e 's/1.2.3.4/192.168.6.9/' my-script


              However, I don't see why you'd want to do that. If you have a machine with a public IP, it probably has a public domain name, so a better plan if the server can be seen via two different IPs is to override DNS using /etc/hosts.



              If the script uses domain name my.server.example.com instead of 1.2.3.4, then this /etc/hosts entry will override it:



              192.168.6.9 my.server.example.com


              That is to say, /etc/hosts doesn't have to be used just for simple host names. It can also override arbitrary domain names.



              Doing it this way means the same script will work from multiple locations without being changed.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                This will replace public IP 1.2.3.4 in place within the file my-script with private IP 192.168.6.9:



                $ sed -i'' -e 's/1.2.3.4/192.168.6.9/' my-script


                However, I don't see why you'd want to do that. If you have a machine with a public IP, it probably has a public domain name, so a better plan if the server can be seen via two different IPs is to override DNS using /etc/hosts.



                If the script uses domain name my.server.example.com instead of 1.2.3.4, then this /etc/hosts entry will override it:



                192.168.6.9 my.server.example.com


                That is to say, /etc/hosts doesn't have to be used just for simple host names. It can also override arbitrary domain names.



                Doing it this way means the same script will work from multiple locations without being changed.






                share|improve this answer












                This will replace public IP 1.2.3.4 in place within the file my-script with private IP 192.168.6.9:



                $ sed -i'' -e 's/1.2.3.4/192.168.6.9/' my-script


                However, I don't see why you'd want to do that. If you have a machine with a public IP, it probably has a public domain name, so a better plan if the server can be seen via two different IPs is to override DNS using /etc/hosts.



                If the script uses domain name my.server.example.com instead of 1.2.3.4, then this /etc/hosts entry will override it:



                192.168.6.9 my.server.example.com


                That is to say, /etc/hosts doesn't have to be used just for simple host names. It can also override arbitrary domain names.



                Doing it this way means the same script will work from multiple locations without being changed.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 15:26









                Warren Young

                54.2k9142145




                54.2k9142145






















                    up vote
                    0
                    down vote













                    I have done by below awk command



                    awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt





                    share|improve this answer




















                    • Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                      – Jeff Schaller
                      Nov 20 at 22:39














                    up vote
                    0
                    down vote













                    I have done by below awk command



                    awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt





                    share|improve this answer




















                    • Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                      – Jeff Schaller
                      Nov 20 at 22:39












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    I have done by below awk command



                    awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt





                    share|improve this answer












                    I have done by below awk command



                    awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 20 at 16:36









                    Praveen Kumar BS

                    1,094138




                    1,094138











                    • Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                      – Jeff Schaller
                      Nov 20 at 22:39
















                    • Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                      – Jeff Schaller
                      Nov 20 at 22:39















                    Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                    – Jeff Schaller
                    Nov 20 at 22:39




                    Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
                    – Jeff Schaller
                    Nov 20 at 22:39


                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?