Sunteți pe pagina 1din 6

HowtoConfigureyourownVPC(VirtualPrivateCloud)inAWS

byPradeepKumarPublishedFebruary28,2017UpdatedFebruary28,2017

WheneverwelogintoourAWS(AmazonWebServices)accountadefaultVPCiscreatedwiththeCIDR(172.31.0.0/16).VPCstands
forVirtualPrivateCloud,itisvirtualprivatenetworkandisisolatedfromothervirtualnetworksinyourAWSaccount,wecan
launchEC2,RDSandElasticCacheinstancesusingourowncreatedVPC.

InthisarticlewewilldemonstratehowtosetupourownVPCinyourAWSaccount.LetsassumeIwanttolaunchtwoec2instances
onewillusedforapplicationserveranditwillbeaccessedovertheInternetandsecondinstancewillbeusedforDatabaseserver.My
applicationinstancewillconnecttoDatabaseinstanceinternallyusingVPCsubnetandalsodontwanttoallowDBinstancetobe
accessedoverinternet.

ReferbeneathstepstosetupVPCandlaunchEC2instancesusingyourVPC
Step1:CreateyourVPC
LogintoyourAWSaccount,FromtheServicesTabSelectVPCthenSelectYourVPCclickonCreateVPC

SpecifyyourVPCNameandCIDR(ClasslessInterDomainRouting),InmycaseIamusingthefollowings

VPCName=LinuxtechiVPC
IPV4CIDR=192.168.0.0/24

ClickonYes,Createoption
Step:2CreatePrivateSubnets
Inthisstepwewillcreatetwoprivatesubnets,Subnet1(192.168.0.0/25)andSubnet2(192.168.0.128/25)acrosstheavailability
zones.WearecallingthesesubnetsasprivatebecausewecantaccessinstancesfromtheInternetwheneverEC2instanceisgetting
IPfromthesesubnets.ThoughafterattachingInternetgatewaytheseinstancesbecomesreachableoverinternet.

FromtheVPCDashboardclickonSubnetsoptionandthenclickonCreateSubnet

Specifythefollowings

Subnetnameassubnet1
VPC(LinuxtechiVPC)
Availabilityzoneasperyourregion
IPV4CIDR192.168.0.0/25

clickonYes,Create,SimilarlyCreateSubnet2withIPV4CIDR192.168.0.128/25
Step:3CreateaRoutetableandassociateitwithyourVPC
FromVPCDashboardthereisanoptioncreateaRoutetable.ClickonCreateRouteTable

SpecifytheNameofRouteTableandSelectyourVPC,InmycaseVPCisLinuxtechiVPC

Step:4CreateInternetGateway(igw)andattachedittoyourVPC
FromVPCdashboardthereisanoptiontocreateInternetgateway.SpecifytheNameofInternetgateway
OncetheInternetgatewayiscreated,attachedittoyourVPC,SelectandRightClickYourInternetgatewayandthenSelectthe
AttachtoVPCoption

NowAddRoutetoyourrouteTableforInternet,gotoRouteTablesOption,SelectyourRouteTable,InmycaseitisLnx
RouteTable,clickonRouteTabandClickonEditandtheclickonaddanotherroute

MentionDestinationIPofInternetas0.0.0.0/0andinthetargetoptionyourInternetgatewaywillbepopulatedautomaticallyas
shownbelow.
ClickonSave

Step:5ChangeRoutetableofyourVPCSubnet
InabovestepswehavecreatedtwoSubnets(Subnet1andSubnet2),IamgoingtochangetheroutetableofSubnet1.FromtheVPC
Dashboard,ClickonSubnets,SelecttheSubnet1andtheclickonRouteTableTabandtheclickonEdit.

ChangethedefaultRoutetabletoLnxRouteTableandthenClickOnSave

NowonwardswheneveranEC2instanceislaunchedinyourVPCusingSubnet1thenwecanaccessthatinstancefromInternetand
Instancelaunchedusingsubnet2willnotaccessibleoverInternetbutitwillbeaccessibleinternally.

Step:6LaunchAPPandDBServerInstanceinyourVPC
LaunchAPPServerinyourVPCusingSubnet1andDBServerusingSubnet2.VerifywhetheryouareabletoaccessAPPServerand
DBserverfrompublicIP.

TrytoSSHAPPServerwithitsPublicIP
TrySSHDBServerwithitsPublicIP

linuxtechi@linuxarena:~/Downloads$ping13.113.116.168
PING13.113.116.168(13.113.116.168)56(84)bytesofdata.
^C
13.113.116.168pingstatistics
8packetstransmitted,0received,100%packetloss,time7056ms
linuxtechi@linuxarena:~/Downloads$sshilinuxtechi.pemec2user@13.113.116.168
ssh:connecttohost13.113.116.168port22:Connectiontimedout
linuxtechi@linuxarena:~/Downloads$

WecantaccesstheDBserverfromInternetbecauseitislaunchedwithSubnet2withitsdefaultRoutetableandInternetgatewayis
notassociatedtoroutetableofSubnet2.ThoughwecanaccesstheDBServerfromAPPserverwithitsprivateIP.

ThatsallforthisarticleandhopeyouguysgotanideahowsetupyourownVPCinyourAWSaccount.Pleasedonthesitatetoshare
yourfeedbackandcomments

S-ar putea să vă placă și