AWS, Recover from IP address change - amazon-web-services

I want to recover from IP address change. My website used to be running fine, but after I allocated elastic IP address, it stopped working I want the website to be running again with new IP address.
So my question is: What steps must I consider and where should I look at first to recover from IP address change?
I can't access that website with old DNS address or new DNS address. Is this DNS issue?
Notes that might be helpful:
My web server seems to be using nginx, and I tried changing the configuration file with new dns, but that doesn't seem to do it.
When I access new domain name, it redirects to old domain name.
when I check with curl using curl -I http://localhost:80, it says HTTP/1.1 301 Moved Permanently

Just as an add on. The problem is this configuration change in your nginx file:
server {
listen 80;
server_name my.old.domain.com;
...
}
Has to be changed to:
server {
listen 80;
server_name my.new.domain.com;
...
}
So the DNS change can take up to 48 hours to propagate (it usually takes 10-30 minutes from experience, depending on your DNS provider)
When the DNS server wasn't propagated nginx would still redirect you to my.old.domain.com
Hope this helps.

Okay, I think it was just time issue.
After changing web server configuration (nginx), I waited around 28 hours and it suddenly started working again.
Source:
Subdomain IP address changed but client still getting directed to old site

Related

Direct IP Attacks, ElastickBeanstalk/NGINX

I have a bit problem with my site.
So setup is ElasticBeanstalk(NGINX) + Cloudflare
But each day around 4AM I have direct IP attack to my server.
Around 300 requests in 1-2 minutes.
Bot try to access some resources like
GET /phpMyadmi/index.php HTTP/1.1
GET /shaAdmin/index.php HTTP/1.1
POST /htfr.php HTTP/1.1
For now all of them going to 80 or 8080 ports.
And successfully handled by Nginx configuration that redirect it to example:443
server {
listen 80 default_server;
listen 8080 default_server;
server_name _;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl on;
...
So questions are,
have many site owners/devOps face the same attack. What is your action to prevent such attacks.
For now it is handled very well and did not affect on server work, should I worry about it? Or just filter out logs with /phpmy/ pattern and forgot about it.
Before this attacks I have request with method PROPFIND, should I blocked it for security reasons? It is handled by default server for now.
I know that I can use Cloudflare Argotunel or ELB + WAF. But I am not really want to do it for now.
I have found one solution on stackoverflow. Is whitelist of all cloudflare ips. But i think it is not a good one.
Also another solution that should work I guess it is to check Host header, and compare it with 'example.com'.
To answer your specific questions:
Every public IP receives unwanted traffic like you describe, sadly its pretty normal. This isnt really an attack as such, its just a bot looking for signs of specific weaknesses, or otherwise trying to provoke a response that contains useful data. This data is no doubt later used in actual attacks, but its basically automated recognisance on a potentially massive scale.
This kind of script likely isnt trying to do any damage, so as long your server is well configured & fully patched its not a big concern. However these kinds of scans are first step towards launching an attack - by identifying services & application versions with known vulnerabilities - so its wise to keep your logs for analysis.
You should follow the principle of least privilege. PROPFIND is related to WebDAV - if you dont use it, disable it (or better white list the verbs you do support and ignore the rest).
If your site is already behind CloudFlare then you really should firewall access to your IP so only Cloudflares IPs can talk to your server. Those IPs do change, so I would suggest a script to download the latest from https://www.cloudflare.com/ips-v4 and have it periodically update your firewall. Theres a slightly vuage help article from CloudFlare on the subject here: https://support.cloudflare.com/hc/en-us/articles/200169166-How-do-I-whitelist-Cloudflare-s-IP-addresses-in-iptables-
If for whatever reason you cant firewall the IP, your next best option is something like fail2ban (www.fail2ban.org) - its a log parser that can manipulate the firewall to temporarily or permanently block an IP address based on patterns found in your log files.
A final thought - id advise against redirecting from your IP to your domain name - your telling the bot/hackers your URL - which they can then use to bypass the CDN and attack your server directly. Unless you have some reason to allow HTTP/HTTPS traffic to your IP address, return a 4XX (maybe 444 a " Connection Closed Without Response") instead of redirecting when requests hit your IP. You should then create a separate server block to handle your redirects, but only have it respond to genuine named URLs.

How to set subdomains whit ip using nginx

Can subdomains be used with ip on Nginx for testing, like teste.x.x.x.x
I did this but does not work.
server_name teste.x.x.x.x teste2.x.x.x.x ;
Thanks
I would say that is not possible, since an IP address is an entity by itself, and subdomains are a feature of DNS's structure or hierarchy.
However, for testing purposes, you could edit you /etc/hosts file, adding the following:
x.x.x.x teste.yourdomain.com
y.y.y.y teste2.yourdomain.com
and this way, accessing teste.yourdomain.com in your browser, would redirect your requests to x.x.x.x

AWS VPC instance doesn't resolve public DNS name

The problem:
My url xyz.co is getting resolved into an ugly AWS public DNS name such as ec2-11-22-33-44.ap-southeast-2.compute.amazonaws.com. It doesn't stick to xyz.co.
Here's what I did:
I have set up my Route 53 configuration according to http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/MigratingDNS.html, so I created an A record pointing to the IP address and a CNAME alias record to allow for www.xyz.co. The domain is sitting with godaddy and the name servers are configured to the AWS delegation set.
The instance itself sits in the default VPC. I double-checked and DNS resolution and DNS host names are both active.
I'm a bit stuck here with this. Any help would be highly appreciated!
Cheers,
Bruno
What you are seeing isn't actually related to name resolution.
It's impossible for DNS to change what appears in the address bar of the web browser -- DNS and web browsers simply do not interact in a way that makes such behavior possible. Your URL is not "getting resolved to" this new value via anything DNS-related, since DNS, configured correctly or incorrectly, can't impact what shows up there, on its own.
The fact that navigating to the IP address has the same impact backs up this assertion.
What you are seeing is not related in any way to DNS or Route 53 or even EC2 or VPC. Your web server is, for whatever reason, configured to redirect incoming requests with any other hostname... over to the hostname you are subsequently seeing in the address bar (which is the one you don't like).
You should notice this in your web server's log. It will be issuing a 301 or 302 redirect on the initial request.
You should also be able to verify this yourself with the curl command line utility. Here, a server accessed as "www.example.com" is redirecting the browser to use its preferred address, "example.com." (Hostnames and addresses are sanitized, but the output is otherwise unmodified.)
$ curl -v www.example.com
* Rebuilt URL to: www.example.com/
* Hostname was NOT found in DNS cache
* Trying 203.0.113.139...
* Connected to www.example.com (203.0.113.139) port 80 (#0)
The next block of output is the request sent to the web server.
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.example.com
> Accept: */*
>
The http response from the web server includes a redirect.
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: http://example.com/
< Connection: close
<
* Closing connection 0
If we were using a browser instead of a command line tool, this would cause the address bar to change to the new value, and establish a new connection to the web server (which might actually be the same one, or a different one... in this case, it's the same).
In spite of the fact that I had typed http://www.example.com into my browser, it would now show only http://example.com/. The same thing would happen if I typed in the IP address if my server was configured to redirect everything to one hostname, as yours appears to be. In my case, it's deliberately configured to do something else.
The above should illustrate that you do not actually have a DNS issue, and explain the mechanism that's causing this to occur (because you may find this to be something useful to do deliberately in the future, as my web servers do -- any www.* request gets stripped and rewritten without the www).
The issue is with your web server, telling the browser to use a different hostname. How to fix that will depend on what web server you are running and why it thinks the redirect is necessary.

Browser DNS behaviour - multiple IP addresses for single domain

I have the following problem and I am struggling to find if a solution exists for it, or what the best practice is here.
I have a site example.com, and multiple servers with different IP addresses around the world. I am seeing the following behaviour in my browser (Chrome) - for simplicity lets say I only have 2 IP addresses for now.
I connect to example.com and data is served from IP address A.B.C.D (server 1). After 40 seconds or, any subsequent request (GET/POST) to example.com then resolves to W.X.Y.Z (server 2). My issue is that I have a cookie based web session on server 1, and server 2 knows nothing about that session. There is no kind of back-end replication I can do to sync state between both servers.
Is there any way I can force the browser to only connect to a single server once a server has served the first page? I am using RR DNS with multiple A records at the moment. Would switching to CNAME solve this problem?
One solution I was thinking of was having each server reply with a configured domain in the http headers (e.g. server1 would reply with X-HEADER: server1.example.com, server2 would reply with X-HEADER: server2.example.com) and then force the browser to make requests to these. I would then have a single IP address for server1.example.com, and another for server2.example.com. Does this break same-origin policy though? If I am on example.com can I send GET/POST/PUT etc. to server1.example.com?
I'd really appreciate any advice on this - I'm so confused!

How to access a website by IP address at AWS Opsworks?

I have many apps deployed per instance at AWS Opsworks. Each app has a domain or subdomain assigned to it.
It works fine when I type the domain/subdomain in the address bar in a web browser.
Although I would like to know how to access the domain/subdomain using the IP address in the address bar?
Eg:
http://[IP_ADDRESS]/[SOME_STRING_TO_ACCESS_DOMAIN_OR_SUBDOMAIN_1.COM]
http://[IP_ADDRESS]/[SOME_STRING_TO_ACCESS_MY_DOMAIN_OR_SUBDOMAIN_2.COM]
http://[IP_ADDRESS]/[SOME_STRING_TO_ACCESS_MY_DOMAIN_OR_SUBDOMAIN_3.COM]
http://[IP_ADDRESS]/[SOME_STRING_TO_ACCESS_MY_DOMAIN_OR_SUBDOMAIN_4.COM]
The web server is 'nginx' + 'unicorn'. Thanks in advance.
Just add the ip as a server name to the server, eg:
server {
server_name example.com 11.22.33.44;
# ...
}
If you want to handle the string after the ip in a different way, like ip/domain_name you need a separate server to handle this
server {
server_name 11.22.33.44;
root /path/to/root/$uri; # for example
# ...
}