Creating custom NAT network in windows container

Creating custom NAT network in windows container

Creating custom NAT network in windows container

In this blog, we will show you creating custom NAT network in windows container using docker commands.

 

INTRODUCTION

The windows container networks are similar to virtual networks like HYPER-V, VMWARE. The container will have virtual NIC which connected to a virtual switch. We can also create our own virtual networks, customize IP address space.

 

NAT NETWORKING OVERVIEW

  • Go to PowerShell window and type the below command to get the network information.

Get-ContainerNetwork

Creating custom NAT network in windows container

 

  • This network (NAT) defined by default while building the container host on windows 2016 server. The subnet that defined for this network is 172.23.176.0/20.  As we spinning up the containers, the virtual NIC in this containers has been gone into this network. So containers have to use this network to reach the internet.

 

WINDOWS CONTAINER NETWORK TYPES

  • There are four types of network types available for docker networking. Go to PowerShell window and type below command to view the help page of new-containernetwork cmdlet.

help new-containernetwork

 

Creating custom NAT network in windows container

 

  • The four network driver options are NAT, Transparent, L2Bridge and L2Tunnel.

NAT – We will get the NAT (Network Address Translation) network by default. The container in this network will be in the isolated network. To reach the internet they need to use the IP address of windows container host.

Transparent –  It’s little bit different to NAT. Each container in this network will get an IP address from the physical network of windows container host. It’s similar to bridged network.

L2Bridge & L2Tunnel – These two networks drivers are using for public and private cloud deployments. It’s great for SDN (Software Defined Network) network environments. Typically we will use L2 type networks in multiple container host environments.

 

  • Go to PowerShell window and type ipconfig command.

Creating custom NAT network in windows container

 

  • You can see the virtual ethernet adapter that has an IP address as 172.23.176.1and subnet mask as 255.255.240.0. Our physical network has the IP address of 192.168.232.80 and subnet mask as 255.255.224.0.

 

  • By default, the containers that we launch in this container host will go to 172 network.
  • Launching a container using docker run command to check the default NAT networking.

docker run –it microsoft/nanoserver

Creating custom NAT network in windows container

 

  • Once the container is up and running, type ipconfig inside the container.

Creating custom NAT network in windows container

 

  • The IP address that has assigned to this container is 172.23.178.150. Since NAT has been configured, we will able to ping the internet domain.

Creating custom NAT network in windows container

 

CREATING CUSTOM NAT NETWORK

  • As if we are using this address space 172.18 already, we can create our own NAT network for our environment. To do that, stop the docker service using below command.

stop-service docker

Creating custom NAT network in windows container

 

  • Remove all the container network using the below command.

Get-ContainerNetwork | Remove-ContainerNetwork

Press A to confirm the deletion.

Creating custom NAT network in windows container

 

  • To customize the address space for NAT network, we need to add the content in the daemon.json file. Use the below command to create the daemon.json file under C:\ProgramData\docker\config folder.

New-Item –ItemType file –Path C:\ProgramData\docker\config –Name daemon.json

Creating custom NAT network in windows container

 

  • Navigate the C:\ProgramData\docker\config folder using invoke-item command.

invoke-item c:\programdata\docker\config

Creating custom NAT network in windows container

 

  • Add the below content in daemon.json file.

{
“fixed-cidr” : “10.0.0.0/24”
}

Creating custom NAT network in windows container

 

  • Save the file and close it.
  • Start the docker service using below command.

Start-Service docker

Creating custom NAT network in windows container

 

  • Docker service is up and running fine. Check the NAT networking status using below command.

Get-ContainerNetwork

Creating custom NAT network in windows container

 

  • The subnet CIDR has been changed to 10.0.0.0/24 network. We have successfully modified network address space.
  • Create a new container and make sure this new network works. Create a new container using the below command.

docker run -it microsoft/nanoserver

Creating custom NAT network in windows container

 

  • Once the container is up and running type ipconfig to check the IP address information.

Creating custom NAT network in windows container

 

  • Also, we are able to ping the internet domain without any problem.

Creating custom NAT network in windows container

 

VIDEO

 

Thanks for reading this blog. We hope it was useful for you to learn how to create a custom NAT networking in windows container.

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn
More Interested Related Posts
zfs pool usage

ZFS Pool and Dataset Usage

ZFS Pool and Dataset Usage   I am back with another blog to provide the useful script to the Freebsd users to determine the zpool

Assistanz Networks

Installing Zabbix Agent in FreeBSD 12.0

Zabbix Agent Installation and Configuration Guide on FreeBSD 12.0   Zabbix is an open-source monitoring software tool for diverse IT components, including networks, servers, virtual

DirectAdmin Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk
$ 99 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • NDA & SLA
  • SLA Review Meetings
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation
  •  

Platinum Support

24/7 Proactive Support
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Support

$ 30 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response Time
  • 4 Hours Resolution time for the Possible Issues
  • Security and Performance Optimization
  • React to Customers queries
  • Simple SignUp Process
  • Instant Account Activation
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support