본문 바로가기
공부/IaC

[Terrafrom] IP Network Functions (cidrhost, cidrnetmask, cidrsubnet, cudrsubnets)

by haejang 2021. 10. 18.
728x90
728x90

 

 

1. cidrhost


https://www.terraform.io/docs/language/functions/cidrhost.html

 

cidrhost - Functions - Configuration Language - Terraform by HashiCorp

The cidrhost function calculates a full host IP address within a given IP network address prefix.

www.terraform.io

주어진 IP 대역에서의 특정번째 호스트 IP 찾기

기본 구조 : cidrhost(prefix, hostnum)

Ex)

cidrhost("10.0.0.0/16", 39)
> 10.0.0.39

cidrhost("192.168.32.96/27", 12)
> 192.168.32.108

 

 

 

2. cidrnetmask


https://www.terraform.io/docs/language/functions/cidrnetmask.html

 

cidrnetmask - Functions - Configuration Language - Terraform by HashiCorp

The cidrnetmask function converts an IPv4 address prefix given in CIDR notation into a subnet mask address.

www.terraform.io

주어진 대역의 netmask 찾기

기본 구조 : cidrnetmask(prefix)

Ex)

cidrnetmask("10.0.0.0/16")
> 255.255.0.0

cidrnetmask("192.168.32.96/27")
> 255.255.255.224

 

 

 

3. cidrsubnet


https://www.terraform.io/docs/language/functions/cidrsubnet.html

 

cidrsubnet - Functions - Configuration Language - Terraform by HashiCorp

The cidrsubnet function calculates a subnet address within a given IP network address prefix.

www.terraform.io

주어진 대역 내에서 새 비트 수에 따른 서브네팅 해줌

기본 구조 : cidrsubnet(prefix, newbits, netnum)

Ex)

cidrsubnet("10.0.0.0/16", 8, 1)
> 10.0.1.0/24
cidrsubnet("10.0.0.0/16", 8, 2)
> 10.0.2.0/24
cidrsubnet("192.168.32.96/27", 3, 1)
> 192.168.32.100/30
cidrsubnet("192.168.32.96/27", 3, 2)
> 192.168.32.104/30

 

 

 

4. cidrsubnets


https://www.terraform.io/docs/language/functions/cidrsubnets.html

 

cidrsubnets - Functions - Configuration Language - Terraform by HashiCorp

The cidrsubnets function calculates a sequence of consecutive IP address ranges within a particular CIDR prefix.

www.terraform.io

위의 cidrsubnet은 동일한 비트로 서브네팅 된 대역들 중 특정 번째의 대역만 출력하는 것

cidrsubnets는 동일하지 않은 비트로 쪼갠 대역들을 모두 출력해준다 (string list 형식)

기본 구조 : cidrsubnets(prefix, newbits...)

Ex)

cidrsubnets("10.0.0.0/16", 4, 8, 8, 4)
> [
    "10.0.0.0/20",
    "10.0.16.0/24",
    "10.0.17.0/24",
    "10.0.32.0/20"
]
      
cidrsubnets("192.168.32.96/27", 3, 2, 3, 4)
> [
    "192.168.32.96/30",
    "192.168.32.104/29",
    "192.168.32.112/30",
    "192.168.32.116/31"
]

 

 

 

 

 

728x90
728x90

댓글