Replace a public IP by a private IP in a shell script [closed]
Clash 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
linux sed
New contributor
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.
add a comment |
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
linux sed
New contributor
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.
add a comment |
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
linux sed
New contributor
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
linux sed
New contributor
New contributor
New contributor
asked Nov 20 at 14:48
Ali EL KANDOUSSI
54
54
New contributor
New contributor
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.
add a comment |
add a comment |
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.
add a comment |
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
Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
– Jeff Schaller
Nov 20 at 22:39
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 20 at 15:26
Warren Young
54.2k9142145
54.2k9142145
add a comment |
add a comment |
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
Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
– Jeff Schaller
Nov 20 at 22:39
add a comment |
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
Be careful to escape the periods so that you don't accidentally match "1j2j3j4j"
– Jeff Schaller
Nov 20 at 22:39
add a comment |
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
I have done by below awk command
awk 'gsub("1.2.3.4","192.168.159.166",$0);print $0' file.txt
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
add a comment |
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
add a comment |