diff --git a/projects/bash_networking_security/SOLUTION b/projects/bash_networking_security/SOLUTION index 2edfbaf..1e8216c 100644 --- a/projects/bash_networking_security/SOLUTION +++ b/projects/bash_networking_security/SOLUTION @@ -1,16 +1,21 @@ Local DNS Server IP ------------------- - + 10.0.0.2 Default gateway IP ------------------- - + 10.0.0.1 DHCP IP allocation sys-logs ------------------- - +Jun 15 15:12:25 ip-10-0-0-41 dhclient[355]: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x73dd755c) +Jun 15 15:12:25 ip-10-0-0-41 dhclient[355]: DHCPOFFER of 10.0.0.41 from 10.0.0.1 + +Jun 15 15:12:25 ip-10-0-0-41 dhclient[355]: DHCPREQUEST for 10.0.0.41 on eth0 to 255.255.255.255 port 67 (xid=0x5c75dd73) + +Jun 15 15:12:25 ip-10-0-0-41 dhclient[355]: DHCPACK of 10.0.0.41 from 10.0.0.1 (xid=0x73dd755c) diff --git a/projects/bash_networking_security/bastion_connect.sh b/projects/bash_networking_security/bastion_connect.sh index a9bf588..6c0e78f 100644 --- a/projects/bash_networking_security/bastion_connect.sh +++ b/projects/bash_networking_security/bastion_connect.sh @@ -1 +1,27 @@ #!/bin/bash +# Check if the KEY_PATH environment variable is set +if [ -z "$KEY_PATH" ]; then + echo "KEY_PATH env var is expected" + exit 5 +fi + +# Check if the public instance IP is provided +if [ -z "$1" ]; then + echo "Please provide bastion IP address" + exit 5 +fi + +# If both public and private instance IPs are provided, connect to the private instance via the public instance +if [ -n "$2" ]; then + if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -i "$KEY_PATH" ubuntu@"$1" stat new_key \> /dev/null 2\>\&1; then + PRIVATE_KEY_FILE="new_key" + else + PRIVATE_KEY_FILE="$KEY_PATH" + fi + + ssh -ti "$KEY_PATH" ubuntu@"$1" ssh -i "$PRIVATE_KEY_FILE" ubuntu@"$2" "$3" + +# Otherwise, connect to the public instance +else + ssh -i "$KEY_PATH" ubuntu@"$1" +fi diff --git a/projects/bash_networking_security/vpc.sh b/projects/bash_networking_security/vpc.sh index 951abba..57e67ff 100644 --- a/projects/bash_networking_security/vpc.sh +++ b/projects/bash_networking_security/vpc.sh @@ -1,4 +1,4 @@ -REGION="" -VPC_ID="" -PUBLIC_INSTANCE_ID="" -PRIVATE_INSTANCE_ID="" \ No newline at end of file +REGION="us-west-1" +VPC_ID="vpc-05495054ca5e34202" +PUBLIC_INSTANCE_ID="i-0a6f8bcf45bd9dcf8" +PRIVATE_INSTANCE_ID="i-02d1d83748e76ebf6"