<alb-one>
<alb-description-one>
<alb-sg-server-one>
EC2-One
<ec2-one>
<one-created-earlier>
#!/bin/bash
sudo yum update -y
sudo yum install nginx -y
sudo service nginx start
echo '<html><body style="background-color:red;"><h1>EC2 RED server</h1></body></html>' | sudo tee /usr/share/nginx/html/index.html > /dev/null
sudo service nginx reload
EC2-Two
<ec2-two>
<one-created-earlier>
#!/bin/bash
sudo yum update -y
sudo yum install nginx -y
sudo service nginx start
echo '<html><body style="background-color:blue;"><h1>EC2 BLUE server</h1></body></html>' | sudo tee /usr/share/nginx/html/index.html > /dev/null
sudo service nginx reload
<alb-target-group-name>
/
<alb-name>
Name: <ec2-one>
AMI: Amazon Linux
Instance type: t2.micro
Key pair (create a new one)
<key-pair-name>
Network settings (click edit)
<sg-name>
<sg-description>
Click on Advanced details
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Welcome to the webServer_Alpha</h1>" > /var/www/html/index.html
Click on Launch instance
Name: <ec2-two>
AMI: Amazon Linux
Instance type: t2.micro
Key pair: select the key pair created in the instance above
Network settings (click edit)
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Welcome to the webServer_Beta</h1>" > /var/www/html/index.html
Ensure the instances are in a running state and all checks have been passed
<tg-name>
<nlb-name>
ssh -i <your-key-name.pem> <ec2-url>
while true; do curl http://<NLB-DNS-NAME>; done
Name: <ec2-one>
AMI: Ubuntu Server 24.04
Key pair (create a new pair)
<path-based-routing>
Network settings
Click Create instance
Name: <ec2-two>
AMI: Ubuntu Server 24.04
Key pair (use the one created in ec2-one)
Network settings
sudo apt update
sudo apt install nginx
sudo vi /var/www/html/demo1.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to App1!</title>
</head>
<body>
<h1>Welcome to App1!</h1>
</body>
</html>
:wq!
sudo vi /var/www/html/demo2.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to App2!</title>
</head>
<body>
<h1>Welcome to App2!</h1>
</body>
</html>
:wq!
<demo>
/demo1.html
, forward to tg1/demo2.html
, forward to tg2http://your-alb-dns-name/demo1.html
http://your-alb-dns-name/demo2.html
<vpc-name>
<public-subnet-name>
<public subnet-name-2>
Navigate to VPC via the AWS Management Console
Create three VPCs
10.0.0.0/16
10.1.0.0/16
10.2.0.0./16
In each VPC, create a subnet
10.0.1.0/24
10.1.1.0/24
10.2.1.0/24
Create an Internet Gateway for each VPC
Modify route tables
0.0.0.0/0
Navigate to the EC2 dashboard and launch three instances with the following configuration
<ec2-name-corresponding-vpc>
<network-name>
<subnet-vpc-corresponding-name>
<sg-vpc-ec2-name>
<sg-for-ec2-vpc>
ping <ec2-private-ipv4-address>
and hit enter<pc-vpc-ec2-name>
<vpc-route-table>
10.1.0.0./16
(change 1 for the other vpcs)
pc-vpc-ec2-name
10.0.0./16
<subnet-name>
10.0.1.0./24
my-igw
0.0.0.0/0
<sg-name>
<sg-description>
<ec2-name>
<vpc-name>
<public-vpc-id>
<public-vpc-subnet-name>
<private-subnet-name>
<internet-gateway-name>
<public-route-table-name>
<previously-created-vpc>
0.0.0.0/0
to target <internet-gateway-name>
<public-subnet-name>
<private-subnet-name>
Public subnet instance
<public-subnet-ec2>
previously created vpc
previously created public subnet
<nat-instance-public-security-group>
<nat-instance-public-sg-description>
Private subnet instance
<private-subnet-ec2>
previously created vpc
previously created private subnet
<nat-instance-private-security-group>
<nat-instance-private-sg-description>
public-nat-instance-security-group
SSH into the public subnet instance
Run the follow commands to enable IP forwarding and configure NAT
sudo vi /etc/sysctl.d/custom-ip-forwarding.conf
net.ipv4.ip_forward=1
:wq!
)sudo sysctl -p /etc/sysctl.d/custom-ip-forwarding.conf
sudo yum install iptables-services -y
netstat -i
sudo iptables -t nat -A POSTROUTING -o enX0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o enX0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o enX0 -j ACCEPT
sudo service iptables save
sudo service iptables restart
In EC2, navigate to the NAT instance
Update the route table of the private subnet, destination 0.0.0.0/0
and the target instance
Update the security for the NAT instance
scp -i <your_NAT_Instance_Key_Pair> <Your_Private_Instance_Key_Pair> ec2-user@<public_IP_address_of_NAT_Instance:/home/ec2-user/
sudo chmod 400 MyKeyPair.pem
ssh -i MyKeyPair.pem ec2-user@<PrivateInstance-Private-IP>
<prefix-list-name>
<sg-name>
<sg-description>
<rt-name>
<vpc-name>