Showing posts with label networking. Show all posts
Showing posts with label networking. Show all posts

Monday, March 21, 2022

AWS Networking & Content Delivery - Route 53




Hosted zone configuration

A hosted zone is a container that holds information about how you want to route traffic for a domain, such as example.com, and its subdomains.

DNS AND ROUTING

user will check from host system first, then if not available, it will go to ISP..

ISP has one DNS server where all the IP, if it doesn’t find in the DNS, it will forward to NS (name) server (.org / .in / .sg) if it doesn’t find, it will go to SOA(start/sign of Authority – metadata: who is the owner? when is this domain created?) server. if SOA server has it, it will give back to DNS and DNS give back to user.


so AWS is using a Route53. it can create a domain. why is it called 53? cause domain name is running on port number 53.

To register a domain, you need a domain registrar(godaddy.com/bigrock.in/AWS) that will help you setup the domain.

whenever you purchase a domain in AWS, there will be a hosted zone. Hosted zone is basically the area where your domain name related activity will be configured.

public hosted zone – internet

private hosted zone – Amazon VPC

how many hosted zone can we add? Maximum 500.

 

Record Types:

1. A record – maps IP (IPV4) address to domain

2. AAAA record – maps IP (IPV6) address to domain

3. Cname – Canonical Name (the other name of your website (ELB or anyother hosted names))

4. Name Server record – by default it will auto create 4 NS - DNS

5. MX record – Mail Exchange



TTL – Time To Live (Cache process)


Routing Policy:

1. Multivalue answer (any one of the IP adress)

2. Geolocation (based on location)

3. Latency based (response time)

4. Weighted (there will be 10 servers, 20 traffic will go to first IP)

5. Failover

6. Simple Routing

 

to delete a hosted zone, you will need to delete all records first.



Sunday, March 20, 2022

AWS Networking & Content Delivery - VPC creating public and private subnet





VPC is region-wise, by default you can create max 5 VPC. Range of IP Address are defined for each VPC.

CIDR Range: Range of IP address in a network.
Example
CIDR:- 192.168.0.0/16
Because we are using /16 so 192.168 will be constant whereas other octates can be changed from 0-255 which means it has 256x256 = 65536 IP Addresses.

Valid IP Address in this Range
192.168.10.20, 192.168.200.10,192.168.2.0/24, 192.168.3.10/21

Invalid IP in the above CIDR
192.168.10.278, 192.169.0.0/24

Reserved IP Addresses in a network
These reserve IP addresses can not be used for EC2 instances:
1. Network IP
2. Broadcast IP
3. Future use IP


Lab

Create a VPC

1. Search for VPC service
2. Click on Your VPC Link
3. Click Create VPC button
4. On this Page define properties related to VPC

Select VPC only option
Name: irfan-vpc
IPV4 CIDR: 10.10.0.0/16
Tenancy : Default

5. Click on Create VPC button

Create Subnets (By Default no subnet get created in the VPC)

1. Click on Subnets link
2. Click on Create subnet

--------------------------------------------------------------------------
3. Set following properties for Public Subnet

  • VPC ID: irfan-vpc
  • Subnet Name: irfan-public-subnet-2a
  • Availability Zone: 2a
  • CIDR: 10.10.1.0/24

4. Click on Create Subnet
----------------------------------------------------------------------------------------
5. Set following properties for Private subnet

  • VPC ID: irfan-vpc
  • Subnet Name: irfan-private-subnet-2b
  • Availability Zone: 2b
  • CIDR: 10.10.2.0/24

6. Click on Create Subnet

Create an Internet Gateway to provide Internet connectivity to Public subnet

1. Click on Internet Gateways

2. Name: IGW1

  • Click on Create Internet Gateway

3. Select Internet Gateway IGW1 and Action--->Attach to VPC and select myvpc-1

Now Internet connectivity is available to myvpc-1 VPC.


Create Route Tables (A default Route table get created for VPC)

1. Click on Route Tables link

2. Click on Create Route table button

--------------------------------------------------------------------------------------------
3. Set the properties
  • Name: Public Route
  • VPC: irfan-vpc
4. Click on Create Route table button

-----------------------------------------------------------------------------------------------
5. Set the properties
  • Name: Private Route
  • VPC: irfan-vpc
6. Click on Create Route Table


Attach subnets to Route tables

1. Select Public Route

2. Select Subnet Associations

3. Click on Edit subnet associations and select Public Subnet 1-a

4. Click on Routes --> Edit Routes--> Add Route

5. Destination: 0.0.0.0/0

6. Target: IGW1

7. click on Save Changes button.

---------------------------------------------------------------------------------------------
1. Select Private Route

2. Select Subnet Associations

3. Click on Edit subnet associations and select Private subnet 1-b




Create EC2 instance in irfan-vpc

1. Create a Public EC2 instance Amazon Linux Image

2. Select VPC as irfan-vpc

3. Select subnet as Public Subnet 1-a

4. Auto assign Public IP: Enable

5. Create new Security Groups for SSH let's call it sshSG.

--------------------------------------------------------------------------------------------

1. Create a Private EC2 instance Amazon Linux Image

2. Select VPC as myvpc-1

3. Select subnet as Private Subnet 1-b

4. Auto assign Public IP: Disable

5. Select sshSG security group


Experiment

1. Private IP addresses are in the defined range of subnets or not.
Ans: yes

2. Both instances can ping to each other with private ip address.
Ans: no UNLESS you add the security group - ICMP:IPV4 !!!
Now if you want to connect to the private subnet,
you need to connect to it via the public subnet:

1. copy the key-pair info (.pem)
2. create the key-pair info into your public subnet:
    vi IrfanSydney.pem
    copy the content over
    save :wq!
3. go to the private instance and click connect, choose via ssh, then it will tell you the steps:
    chmod 400 IrfanSydney.pem
    ssh -i "IrfanSydney.pem" ec2-user@10.10.2.184

Sunday, March 13, 2022

ASSIGNMENTS: Docker Network Part 1 (Using Custom Network)

 


Challenge: Create a bridge network and run a web app container which stores the data in a database container.

Docker images:
webapp: ramansharma95/webapp
db: ramansharma95/mysql

webapp: This image is used as a webserver container which runs on apache. There is an index.php file hosted on this server in this directory (/var/www/html/index.php) and it is a simple webform to enter details in the database container.

db: This image is used as database container which runs on mysql and stores the data recorded/collected/received from the webserver - webapp. This database container's details should be a part of webapp's connection string.

For webapp container to be connected and functional, we need to create a database called company and a table in the company database called employee which has name, mobile fields IN the db container.

Thursday, March 10, 2022

ASSIGNMENTS: Docker Network Part 3 (None Network)


 


None Network

When no IP address is assigned to the container you can run the container in none network. It is mostly used for applications that need to be tested in an isolated environment. After testing, we can disconnect the container from the network and connect it to another network.


Step 1: Create a centos container on none or null network

docker container run -it --name c1 --network none -d centos

Step 2: Inspect the container and verify that it is running on none networks

docker inspect c1

Step 3: Once the testing is done then remove none network from n1 container and attach bridge network

docker network disconnect none c1

docker network connect bridge c1

Step 4: Verify the n1 container is having bridge network

docker inspect c1

Docker Networking


Summary:
1) Bridge Network: Default & Custom
2) Host Network
3) None/Null Network


DOCKER NETWORKING 
In Docker, if 2 containers communicate to each other, it means they are in a network.

Do note that unlike centos, ubuntu does not have ping command in-built. so you need to install it in the containers themselves:

apt-get update
apt-get install iputils-ping  # 333kb 

 

To look at available docker network commands:

Command:-> docker network --help

connect

Connect a container to a network

create

Create a network

disconnect

Disconnect a container from a network

inspect

Display detailed information on one or more networks

ls

List networks

prune

Remove all unused networks

rm

Remove one or more networks


To find all the IP addresses on a system

Command:-> ip a

Find all the networks in docker

Command:-> docker network ls

Types of Networks in Docker

1) Bridge

1a) Default Bridge Network

It is the default network (docker0) in docker, which means if a container is created by default it is created on top of bridge network docker0.

If 2 or more containers get created on the bridge network then they are automatically in the same network, which means they can communicate with each other.

Step 1:- Create container c1 with ubuntu image

docker container run -it --name c1 -d ubuntu

Step 2:- Check c1 container is running on the docker0 network

ip a

you will find one veth.... on docker0

Also, check the CIDR for docker0


Step 3:- Check the IP address of the container, it should be in the CIDR range of the docker0 network. In my case, IP address of c2 is "172.17.0.2"

docker container inspect c1

Step 4:- Create container c2 with centos image

docker container run -it --name c2 -d centos

Step 5:- Check c2 container is running on the docker0 network

ip a

you will find one more veth.... on docker0

Also, check the CIDR for docker0


Step 6:- Check the IP address of the container, it should be in the CIDR range of the docker0 network. In my case IP address of c2 is "172.17.0.3"

docker container inspect c2

Step 7:- Check container c2 ping to c1. It should get a reply from c1 because both are in the same network (default bridge network)

docker exec -it c2 bash

ping 172.17.0.2

 

1b) Custom Bridge Network or User Define Bridge Network

When a network which is created by user or sysadmin so that specified containers can run on it then it is a custom bridge network.

To make your own custom bridge network, follow the steps below:
Step 1: List all the containers

docker network ls

Step 2: Create a new default Bridge network br1 (-d is drive)

docker network create -d bridge br1

Step 3: Verify network is created successfully. It should be listed in docker networks.

docker network ls

Step 4: Inspect br1 network to find more detailed information.

docker network inspect br1

  •         "Driver": "bridge",
  •         "EnableIPv6": false,
  •         "IPAM": {
  •             "Driver": "default",
  •             "Options": {},
  •             "Config": [
  •                 {
  •                     "Subnet": "172.18.0.0/16",
  •                     "Gateway": "172.18.0.1"


Step 4.2: You can create a bridge network with your own subnet

docker network create -d bridge --subnet=192.168.0.0/16 --gateway=192.168.0.1 br2

docker inspect br2

  •         "Driver": "bridge",
  •         "EnableIPv6": false,
  •         "IPAM": {
  •             "Driver": "default",
  •             "Options": {},
  •             "Config": [
  •                 {
  •                     "Subnet": "192.168.0.0/16",
  •                     "Gateway": "192.168.0.1"
  •                 }

It means if the containers get created on this network layer then they have IP addresses in 192.168.0.1/16 range.

Step 6:- Create a container on top of br1 network on ubuntu base image.

docker container run -it --name c1 --network br1 -d ubuntu

Step 7: Inspect the container and it should have IP address within the br1 CIDR range.

docker container inspect c1

Step 8: Remove the container and network.

docker rm -f c1

docker network rm br1

docker network ls

Monday, February 28, 2022

ASSIGNMENTS: Docker Network Part 2 (Using Host Network)


Step 1: Download required images

docker pull ramansharma95/webapp
docker pull ramansharma95/mysql

Step 2: Create a webapp container with network as host and DO NOT DO a port forwarding on port number 80 as per custom network cause this assignment is run on host network.

docker container run -it --name web --network host -d ramansharma95/webapp

Go to browser and check that you are able to see the default web page. localhost:80

Step 3: Go inside the container (web) and check the code for index.php cause you will need to edit it a little.

docker exec -it web bash

vi /var/www/html/index.php

edit the username from db to host ip address (192.168.33.10).
# you will find that in the index.php, it has connection configs to connect to a server named 'db' but need to edit to host ip address cause its on the same network and also the required username and password to enter that server.

Step 4:- Create a db container with network defined (note this does not require port forwarding)

docker container run -it --name db --network host -d ramansharma95/mysql

Step 5:- Go inside the container (db).

docker exec -it db bash

5.2 connect to mysql with username root and password whizlabs

mysql -uroot -pwhizlabs

5.3 Create a database company

show databases;

create database company;

show databases;

5.4 Create a table employee with name and mobile field.

use company;

create table employee ( name varchar(30), mobile varchar(30) );

5.5 Show all the records in this table

select * from employee;

Step 6: Go to browser and add some employees details in the webpage and check again records in employee table, it should have those records added.

Step 7: Show all the records in this table.

select * from employee;




Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...