Add second VMKernel interface to multiple ESXi hosts

I have to add a VMKernel interface for NAS traffic to a series of hosts that I just built. I am going to call the portgroup NAS as that is the purpose. The portgroup will be in vSwitch0 along with the MGMT network.

These are the commands I need

esxcli network vswitch standard portgroup add -p NAS -v vSwitch0
esxcfg-vmknic -a -i a.b.c.d -n 255.255.255.0 -p NAS
esxcli network ip interface  set -i vmk1 -m 9000    

But I need to run this through a series of hosts. I place the hostnames and IPs in a file in this format.

$ cat nas_ip
host1      IP
host2      IP
host2      IP
host2      IP

Next I generate the ssh command for each host.

cat nas_ip | awk '{print "ssh "$1 " esxcfg-vmknic -a -i " $2 " -n 255.255.255.0 -p NAS" }'
cat nas_ip | awk '{print "ssh "$1 " esxcfg-vmknic -a -i " $2 " -n 255.255.255.0 -p NAS" }' > createvmks.sh
chmod +x createvmks.sh
./createvmks.sh

Finally, I have to enable Jumbo Frame for each NAS VMkernel interface

 for i in `cat list`
 do 
    ssh -q $i "esxcli network ip interface  set -i vmk1 -m 9000"
 done

This example assume you use ssh keys for passwordless login. If you don’t you can use sshpass, I have an example here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s