Friday, March 31, 2017

Amazon EC2 customization

TimeZone
ln -sf /usr/share/zoneinfo/Canada/Eastern /etc/localtime
Edit /etc/sysconfig/clock
ZONE="Canada/Eastern"

iptables
Amazon Linux would not let me bind port < 1024, so we have to use iptables to rediect 80 to 8080 and 443 to 8443. First, create the rules and save them to this file,iptables.dump
# Generated by iptables-save v1.4.18 on Fri Mar 31 03:06:30 2017
*filter
:INPUT ACCEPT [97187:40139959]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [121395:162261294]
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 8443 -j ACCEPT
COMMIT
# Completed on Fri Mar 31 03:06:30 2017
# Generated by iptables-save v1.4.18 on Fri Mar 31 03:06:30 2017
*nat
:PREROUTING ACCEPT [1072:59746]
:INPUT ACCEPT [1601:90978]
:OUTPUT ACCEPT [8974:551695]
:POSTROUTING ACCEPT [8974:551695]
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
-A PREROUTING -i eth0 -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
COMMIT
# Completed on Fri Mar 31 03:06:30 2017

Next, load the rules into iptables
iptables-restore < iptables.dump 

Save the rules
service iptables save

In the default configuration, stopping or restarting the iptables service will discard the running configuration. This behavior can be changed by setting IPTABLES_SAVE_ON_STOP="yes" or IPTABLES_SAVE_ON_RESTART="yes" in /etc/sysconfig/iptables-config. If these values are set, the affected files are:
/etc/sysconfig/iptables

No comments:

Post a Comment