# How do I configure /etc/network/interfaces using chef?

**URL:** <https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142>\
**Category:** Chef Infra (archive)\
**Created:** [March 19, 2014, 3:10pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142 "2014-03-19T15:10:33Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maciek\_Misztal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maciek_misztal/32/351_2.png) [@Maciek\_Misztal](https://discourse.chef.io/u/Maciek_Misztal)\
**Post date:** [March 19, 2014, 3:10pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/1 "2014-03-19T15:10:33Z")

</div>

I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network  
interfaces each - since I’m a complete newb, what is the proper way to do  
it?

Regards,  
Maciej

---

<div class="post-metadata">

**Author:** ![Kenneth\_Barry](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@Kenneth\_Barry](https://discourse.chef.io/u/Kenneth_Barry)\
**Post date:** [March 19, 2014, 4:08pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/2 "2014-03-19T16:08:56Z")

</div>

I'm going to take an initial whack at this, and say I "think" its going to  
be something like

node[network][interfaces].each do |nic|  
[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help  
ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:

> I'm looking for a way to configure N (N=3) ubuntu nodes with 2 network  
> interfaces each - since I'm a complete newb, what is the proper way to do  
> it?
> 
> Regards,  
> Maciej

---

<div class="post-metadata">

**Author:** ![Eric\_Herot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_herot/32/84_2.png) [@Eric\_Herot](https://discourse.chef.io/u/Eric_Herot)\
**Post date:** [March 19, 2014, 4:25pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/3 "2014-03-19T16:25:26Z")

</div>

Not sure if this is useful for your particular case but if what you’re trying to do is set up some existing physical NICs (or virtual NICs if you’re in a cloud computing environment) there is a cookbook for that:

## [https://github.com/redguide/network\_interfaces](https://github.com/redguide/network_interfaces)

Eric

On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com)) wrote:

I’m going to take an initial whack at this, and say I “think” its going to be something like

node[network][interfaces].each do |nic|  
[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network interfaces each - since I’m a complete newb, what is the proper way to do it?

Regards,  
Maciej

---

<div class="post-metadata">

**Author:** ![Maciek\_Misztal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maciek_misztal/32/351_2.png) [@Maciek\_Misztal](https://discourse.chef.io/u/Maciek_Misztal)\
**Post date:** [March 19, 2014, 6:04pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/4 "2014-03-19T18:04:58Z")

</div>

Are there some usage examples? This cookbook's documentation is severely  
lacking - I'm not proficient with Chef yet, so I'm having a hard time  
understanding how to use it.

cheers,  
Maciej

On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:

> Not sure if this is useful for your particular case but if what you're  
> trying to do is set up some existing physical NICs (or virtual NICs if  
> you're in a cloud computing environment) there is a cookbook for that:
> 
> ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> 
> Eric
> 
> On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> wrote:
> 
> I'm going to take an initial whack at this, and say I "think" its going  
> to be something like
> 
> node[network][interfaces].each do |nic|  
> [whatever you want to do here]
> 
> Youll probably wanna add a bit of logic just after that first line to help  
> ignore it is the nic is the lo nic.
> 
> Other will certainly improve on this.
> 
> On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> 
> > I'm looking for a way to configure N (N=3) ubuntu nodes with 2 network  
> > interfaces each - since I'm a complete newb, what is the proper way to do  
> > it?
> > 
> > Regards,  
> > Maciej

---

<div class="post-metadata">

**Author:** ![Bvessemont](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bvessemont/32/132_2.png) [@Bvessemont](https://discourse.chef.io/u/Bvessemont)\
**Post date:** [March 20, 2014, 12:53pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/5 "2014-03-20T12:53:05Z")

</div>

Ohai !

I'm working regularly with this cookbook's author. Don't hesitate to create  
a github issue asking for some doc if you feel the need to.

Actually I'm using this very simple resource to manage my server's eth0 :

network\_interfaces 'eth0' do  
target '10.10.16.203'  
mask '255.255.128.0'  
gateway '10.10.1.253'  
end

there is other options you can use, you'd better look at lwrp ressource  
file to understand how it can work, and what can be changed :

attribute :device, kind\_of: String, name\_attribute: true  
attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]  
attribute :bond, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bond\_mode, kind\_of: String  
attribute :vlan\_dev, kind\_of: String  
attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true  
attribute :bootproto, kind\_of: String  
attribute :target, kind\_of: String  
attribute :gateway, kind\_of: String  
attribute :metric, kind\_of: Integer  
attribute :mtu, kind\_of: Integer  
attribute :mask, kind\_of: String  
attribute :network, kind\_of: String  
attribute :broadcast, kind\_of: String  
attribute :pre\_up, kind\_of: String  
attribute :up, kind\_of: String  
attribute :post\_up, kind\_of: String  
attribute :pre\_down, kind\_of: String  
attribute :down, kind\_of: String  
attribute :post\_down, kind\_of: String  
attribute :custom, kind\_of: Hash

On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:

> Are there some usage examples? This cookbook's documentation is severely  
> lacking - I'm not proficient with Chef yet, so I'm having a hard time  
> understanding how to use it.
> 
> cheers,  
> Maciej
> 
> On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> 
> > Not sure if this is useful for your particular case but if what you’re  
> > trying to do is set up some existing physical NICs (or virtual NICs if  
> > you’re in a cloud computing environment) there is a cookbook for that:
> > 
> > ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> > 
> > Eric
> > 
> > On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> > wrote:
> > 
> > I'm going to take an initial whack at this, and say I "think" its  
> > going to be something like
> > 
> > node[network][interfaces].each do |nic|  
> > [whatever you want to do here]
> > 
> > Youll probably wanna add a bit of logic just after that first line to  
> > help ignore it is the nic is the lo nic.
> > 
> > Other will certainly improve on this.
> > 
> > On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> > 
> > > I'm looking for a way to configure N (N=3) ubuntu nodes with 2 network  
> > > interfaces each - since I'm a complete newb, what is the proper way to do  
> > > it?
> > > 
> > > Regards,  
> > > Maciej

--  
Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
Ingénieur en informatique diplômé de l'UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Sean\_OMeara1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_omeara1/32/207_2.png) [@Sean\_OMeara1](https://discourse.chef.io/u/Sean_OMeara1)\
**Post date:** [March 20, 2014, 1:38pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/6 "2014-03-20T13:38:14Z")

</div>

The best and easiest place to start is "how do you configure them without  
Chef?"

You manipulate files under /etc.

With Chef, you'd start by identifying those files, and putting them under  
Chef management.

# In a recipe

template '/etc/network/interfaces' do  
action :create  
source 'interfaces.erb'  
end

# copy yourserver:/etc/network/interfaces into your cookbook under

templates/default/interfaces.erb

From, there you can start rendering data into this templates.

template '/etc/network/interfaces' do  
action :create  
source 'interfaces.erb'  
variables(

)  
end

On Wed, Mar 19, 2014 at 11:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:

> I'm looking for a way to configure N (N=3) ubuntu nodes with 2 network  
> interfaces each - since I'm a complete newb, what is the proper way to do  
> it?
> 
> Regards,  
> Maciej

---

<div class="post-metadata">

**Author:** ![Sean\_OMeara1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_omeara1/32/207_2.png) [@Sean\_OMeara1](https://discourse.chef.io/u/Sean_OMeara1)\
**Post date:** [March 20, 2014, 1:42pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/7 "2014-03-20T13:42:49Z")

</div>

er, accidentally sent that email before I was done writing it.

template '/etc/network/interfaces' do  
action :create  
source 'interfaces.erb'  
variables(  
eth0\_ip =\> '1.2.3.4',  
eth1\_ip =\> '5.6.7.8',  
eth2\_ip =\> '9.10.11.12'  
)  
end

Then, in the interfaces.erb, dig it out with ERB templating:

Hello eth0's ip is \<%= @eth0\_ip %\>  
Hello eth1's ip is \<%= @eth1\_ip %\>  
Hello eth2's ip is \<%= @eth2\_ip %\>

Iterate this way until you're done.

Consuming a random cookbook you found on the community site like that may  
or may not work for you. That's going to require knowledge of Chef, the  
cookbook, AND ubuntu network configuration.

If you have all three, great. If not, you may want to start more simply.

-s

On Thu, Mar 20, 2014 at 9:38 AM, Sean OMeara [someara@opscode.com](mailto:someara@opscode.com) wrote:

> The best and easiest place to start is "how do you configure them without  
> Chef?"
> 
> You manipulate files under /etc.
> 
> With Chef, you'd start by identifying those files, and putting them under  
> Chef management.
> 
> # In a recipe
> 
> template '/etc/network/interfaces' do  
> action :create  
> source 'interfaces.erb'  
> end
> 
> # copy yourserver:/etc/network/interfaces into your cookbook under
> 
> templates/default/interfaces.erb
> 
> From, there you can start rendering data into this templates.
> 
> template '/etc/network/interfaces' do  
> action :create  
> source 'interfaces.erb'  
> variables(
> 
> )  
> end
> 
> On Wed, Mar 19, 2014 at 11:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> 
> > I'm looking for a way to configure N (N=3) ubuntu nodes with 2 network  
> > interfaces each - since I'm a complete newb, what is the proper way to do  
> > it?
> > 
> > Regards,  
> > Maciej

---

<div class="post-metadata">

**Author:** ![Maciek\_Misztal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maciek_misztal/32/351_2.png) [@Maciek\_Misztal](https://discourse.chef.io/u/Maciek_Misztal)\
**Post date:** [March 20, 2014, 4:17pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/8 "2014-03-20T16:17:46Z")

</div>

there already is such an issue - unattended 😉

On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont  
[bvessemont@gmail.com](mailto:bvessemont@gmail.com)wrote:

> Ohai !
> 
> I'm working regularly with this cookbook's author. Don't hesitate to  
> create a github issue asking for some doc if you feel the need to.
> 
> Actually I'm using this very simple resource to manage my server's eth0 :
> 
> network\_interfaces 'eth0' do  
> target '10.10.16.203'  
> mask '255.255.128.0'  
> gateway '10.10.1.253'  
> end
> 
> there is other options you can use, you'd better look at lwrp ressource  
> file to understand how it can work, and what can be changed :
> 
> attribute :device, kind\_of: String, name\_attribute: true  
> attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]  
> attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]  
> attribute :bond, kind\_of: [TrueClass, FalseClass, Array]  
> attribute :bond\_mode, kind\_of: String  
> attribute :vlan\_dev, kind\_of: String  
> attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true  
> attribute :bootproto, kind\_of: String  
> attribute :target, kind\_of: String  
> attribute :gateway, kind\_of: String  
> attribute :metric, kind\_of: Integer  
> attribute :mtu, kind\_of: Integer  
> attribute :mask, kind\_of: String  
> attribute :network, kind\_of: String  
> attribute :broadcast, kind\_of: String  
> attribute :pre\_up, kind\_of: String  
> attribute :up, kind\_of: String  
> attribute :post\_up, kind\_of: String  
> attribute :pre\_down, kind\_of: String  
> attribute :down, kind\_of: String  
> attribute :post\_down, kind\_of: String  
> attribute :custom, kind\_of: Hash
> 
> On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> 
> > Are there some usage examples? This cookbook's documentation is severely  
> > lacking - I'm not proficient with Chef yet, so I'm having a hard time  
> > understanding how to use it.
> > 
> > cheers,  
> > Maciej
> > 
> > On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> > 
> > > Not sure if this is useful for your particular case but if what you're  
> > > trying to do is set up some existing physical NICs (or virtual NICs if  
> > > you're in a cloud computing environment) there is a cookbook for that:
> > > 
> > > ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> > > 
> > > Eric
> > > 
> > > On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> > > wrote:
> > > 
> > > I'm going to take an initial whack at this, and say I "think" its  
> > > going to be something like
> > > 
> > > node[network][interfaces].each do |nic|  
> > > [whatever you want to do here]
> > > 
> > > Youll probably wanna add a bit of logic just after that first line to  
> > > help ignore it is the nic is the lo nic.
> > > 
> > > Other will certainly improve on this.
> > > 
> > > On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> > > 
> > > > I'm looking for a way to configure N (N=3) ubuntu nodes with 2  
> > > > network interfaces each - since I'm a complete newb, what is the proper way  
> > > > to do it?
> > > > 
> > > > Regards,  
> > > > Maciej
> 
> --  
> Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
> Ingénieur en informatique diplômé de l'UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Eric\_Herot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_herot/32/84_2.png) [@Eric\_Herot](https://discourse.chef.io/u/Eric_Herot)\
**Post date:** [March 20, 2014, 6:50pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/9 "2014-03-20T18:50:11Z")

</div>

Hi Maciek,

Definitely agree about the docs. I have a Trello card open right now to deal with that in the next few weeks.

## Barthélemy’s example will probably serve your purposes but in case it doesn’t, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.

Eric

On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

there already is such an issue - unattended 😉

On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont [bvessemont@gmail.com](mailto:bvessemont@gmail.com) wrote:  
Ohai !

I’m working regularly with this cookbook’s author. Don’t hesitate to create a github issue asking for some doc if you feel the need to.

Actually I’m using this very simple resource to manage my server’s eth0 :

network\_interfaces ‘eth0’ do  
target '10.10.16.203’  
mask '255.255.128.0’  
gateway '10.10.1.253’  
end

there is other options you can use, you’d better look at lwrp ressource file to understand how it can work, and what can be changed :  
attribute :device, kind\_of: String, name\_attribute: true

attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]

attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]

attribute :bond, kind\_of: [TrueClass, FalseClass, Array]

attribute :bond\_mode, kind\_of: String  
attribute :vlan\_dev, kind\_of: String  
attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true

attribute :bootproto, kind\_of: String  
attribute :target, kind\_of: String  
attribute :gateway, kind\_of: String

attribute :metric, kind\_of: Integer  
attribute :mtu, kind\_of: Integer  
attribute :mask, kind\_of: String

attribute :network, kind\_of: String  
attribute :broadcast, kind\_of: String  
attribute :pre\_up, kind\_of: String

attribute :up, kind\_of: String  
attribute :post\_up, kind\_of: String  
attribute :pre\_down, kind\_of: String

attribute :down, kind\_of: String  
attribute :post\_down, kind\_of: String  
attribute :custom, kind\_of: Hash

On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
Are there some usage examples? This cookbook’s documentation is severely lacking - I’m not proficient with Chef yet, so I’m having a hard time understanding how to use it.

cheers,  
Maciej

On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:  
Not sure if this is useful for your particular case but if what you’re trying to do is set up some existing physical NICs (or virtual NICs if you’re in a cloud computing environment) there is a cookbook for that:

## [https://github.com/redguide/network\_interfaces](https://github.com/redguide/network_interfaces)

Eric

On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com)) wrote:

I’m going to take an initial whack at this, and say I “think” its going to be something like

node[network][interfaces].each do |nic|  
[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network interfaces each - since I’m a complete newb, what is the proper way to do it?

Regards,  
Maciej

–  
Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
Ingénieur en informatique diplômé de l’UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Guy\_Matz](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Guy\_Matz](https://discourse.chef.io/u/Guy_Matz)\
**Post date:** [March 20, 2014, 7:32pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/10 "2014-03-20T19:32:07Z")

</div>

I would suggest that you don't use chef for this. Instead, put the  
creation of interfaces into your build process, e.g. kickstart

On Thu, Mar 20, 2014 at 2:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:

> Hi Maciek,
> 
> Definitely agree about the docs. I have a Trello card open right now to  
> deal with that in the next few weeks.
> 
> ## Barthélemy's example will probably serve your purposes but in case it doesn't, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.
> 
> Eric
> 
> On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com))  
> wrote:
> 
> there already is such an issue - unattended 😉
> 
> On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont \<  
> [bvessemont@gmail.com](mailto:bvessemont@gmail.com)\> wrote:
> 
> > Ohai !
> > 
> > I'm working regularly with this cookbook's author. Don't hesitate to  
> > create a github issue asking for some doc if you feel the need to.
> > 
> > Actually I'm using this very simple resource to manage my server's eth0 :
> > 
> > network\_interfaces 'eth0' do  
> > target '10.10.16.203'  
> > mask '255.255.128.0'  
> > gateway '10.10.1.253'  
> > end
> > 
> > there is other options you can use, you'd better look at lwrp ressource  
> > file to understand how it can work, and what can be changed :  
> > attribute :device, kind\_of: String, name\_attribute: true
> > 
> > attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]
> > 
> > attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]
> > 
> > attribute :bond, kind\_of: [TrueClass, FalseClass, Array]
> > 
> > attribute :bond\_mode, kind\_of: String  
> > attribute :vlan\_dev, kind\_of: String  
> > attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true
> > 
> > attribute :bootproto, kind\_of: String  
> > attribute :target, kind\_of: String  
> > attribute :gateway, kind\_of: String
> > 
> > attribute :metric, kind\_of: Integer  
> > attribute :mtu, kind\_of: Integer  
> > attribute :mask, kind\_of: String
> > 
> > attribute :network, kind\_of: String  
> > attribute :broadcast, kind\_of: String  
> > attribute :pre\_up, kind\_of: String
> > 
> > attribute :up, kind\_of: String  
> > attribute :post\_up, kind\_of: String  
> > attribute :pre\_down, kind\_of: String
> > 
> > attribute :down, kind\_of: String  
> > attribute :post\_down, kind\_of: String  
> > attribute :custom, kind\_of: Hash
> > 
> > On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> > 
> > > Are there some usage examples? This cookbook's documentation is  
> > > severely lacking - I'm not proficient with Chef yet, so I'm having a hard  
> > > time understanding how to use it.
> > > 
> > > cheers,  
> > > Maciej
> > > 
> > > On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> > > 
> > > > Not sure if this is useful for your particular case but if what  
> > > > you're trying to do is set up some existing physical NICs (or virtual NICs  
> > > > if you're in a cloud computing environment) there is a cookbook for that:
> > > > 
> > > > ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> > > > 
> > > > Eric
> > > > 
> > > > On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> > > > wrote:
> > > > 
> > > > I'm going to take an initial whack at this, and say I "think" its  
> > > > going to be something like
> > > > 
> > > > node[network][interfaces].each do |nic|  
> > > > [whatever you want to do here]
> > > > 
> > > > Youll probably wanna add a bit of logic just after that first line to  
> > > > help ignore it is the nic is the lo nic.
> > > > 
> > > > Other will certainly improve on this.
> > > > 
> > > > On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal \<[mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)
> > > > 
> > > > > wrote:
> > > > 
> > > > > I'm looking for a way to configure N (N=3) ubuntu nodes with 2  
> > > > > network interfaces each - since I'm a complete newb, what is the proper way  
> > > > > to do it?
> > > > > 
> > > > > Regards,  
> > > > > Maciej
> > 
> > --  
> > Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
> > Ingénieur en informatique diplômé de l'UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Booker\_Bense](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/booker_bense/32/117_2.png) [@Booker\_Bense](https://discourse.chef.io/u/Booker_Bense)\
**Post date:** [March 20, 2014, 9:55pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/11 "2014-03-20T21:55:33Z")

</div>

I'd double vote this suggestion. There is a huge chicken and egg problem in  
using a network based CM to manage the network interfaces.  
We've been using such a system ( not chef ) for 10 years and it causes as  
many problems as it solves.

If you need to automate the network config, then you need something like  
Cobbler.

- Booker C. Bense

On Thu, Mar 20, 2014 at 12:32 PM, Guy Matz [guymatz@gmail.com](mailto:guymatz@gmail.com) wrote:

> I would suggest that you don't use chef for this. Instead, put the  
> creation of interfaces into your build process, e.g. kickstart
> 
> On Thu, Mar 20, 2014 at 2:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> 
> > Hi Maciek,
> > 
> > Definitely agree about the docs. I have a Trello card open right now to  
> > deal with that in the next few weeks.
> > 
> > ## Barthélemy's example will probably serve your purposes but in case it doesn't, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.
> > 
> > Eric
> > 
> > On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com))  
> > wrote:
> > 
> > there already is such an issue - unattended 😉
> > 
> > On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont \<  
> > [bvessemont@gmail.com](mailto:bvessemont@gmail.com)\> wrote:
> > 
> > > Ohai !
> > > 
> > > I'm working regularly with this cookbook's author. Don't hesitate to  
> > > create a github issue asking for some doc if you feel the need to.
> > > 
> > > Actually I'm using this very simple resource to manage my server's eth0 :
> > > 
> > > network\_interfaces 'eth0' do  
> > > target '10.10.16.203'  
> > > mask '255.255.128.0'  
> > > gateway '10.10.1.253'  
> > > end
> > > 
> > > there is other options you can use, you'd better look at lwrp ressource  
> > > file to understand how it can work, and what can be changed :  
> > > attribute :device, kind\_of: String, name\_attribute: true
> > > 
> > > attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]
> > > 
> > > attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]
> > > 
> > > attribute :bond, kind\_of: [TrueClass, FalseClass, Array]
> > > 
> > > attribute :bond\_mode, kind\_of: String  
> > > attribute :vlan\_dev, kind\_of: String  
> > > attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true
> > > 
> > > attribute :bootproto, kind\_of: String  
> > > attribute :target, kind\_of: String  
> > > attribute :gateway, kind\_of: String
> > > 
> > > attribute :metric, kind\_of: Integer  
> > > attribute :mtu, kind\_of: Integer  
> > > attribute :mask, kind\_of: String
> > > 
> > > attribute :network, kind\_of: String  
> > > attribute :broadcast, kind\_of: String  
> > > attribute :pre\_up, kind\_of: String
> > > 
> > > attribute :up, kind\_of: String  
> > > attribute :post\_up, kind\_of: String  
> > > attribute :pre\_down, kind\_of: String
> > > 
> > > attribute :down, kind\_of: String  
> > > attribute :post\_down, kind\_of: String  
> > > attribute :custom, kind\_of: Hash
> > > 
> > > On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> > > 
> > > > Are there some usage examples? This cookbook's documentation is  
> > > > severely lacking - I'm not proficient with Chef yet, so I'm having a hard  
> > > > time understanding how to use it.
> > > > 
> > > > cheers,  
> > > > Maciej
> > > > 
> > > > On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> > > > 
> > > > > Not sure if this is useful for your particular case but if what  
> > > > > you're trying to do is set up some existing physical NICs (or virtual NICs  
> > > > > if you're in a cloud computing environment) there is a cookbook for that:
> > > > > 
> > > > > ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> > > > > 
> > > > > Eric
> > > > > 
> > > > > On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> > > > > wrote:
> > > > > 
> > > > > I'm going to take an initial whack at this, and say I "think" its  
> > > > > going to be something like
> > > > > 
> > > > > node[network][interfaces].each do |nic|  
> > > > > [whatever you want to do here]
> > > > > 
> > > > > Youll probably wanna add a bit of logic just after that first line to  
> > > > > help ignore it is the nic is the lo nic.
> > > > > 
> > > > > Other will certainly improve on this.
> > > > > 
> > > > > On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal \<  
> > > > > [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)\> wrote:
> > > > > 
> > > > > > I'm looking for a way to configure N (N=3) ubuntu nodes with 2  
> > > > > > network interfaces each - since I'm a complete newb, what is the proper way  
> > > > > > to do it?
> > > > > > 
> > > > > > Regards,  
> > > > > > Maciej
> > > 
> > > --  
> > > Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
> > > Ingénieur en informatique diplômé de l'UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Maciek\_Misztal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maciek_misztal/32/351_2.png) [@Maciek\_Misztal](https://discourse.chef.io/u/Maciek_Misztal)\
**Post date:** [March 20, 2014, 10:04pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/12 "2014-03-20T22:04:12Z")

</div>

Hi Eric,

If you would be so kind and elaborate :

How would you configure multiple nodes with multiple interfaces using this  
cookbook? Can you give me a simple 2 nodes with 2 interfaces each example?

Please assume that I know little of chef and I'm trying to understand how  
to "model" the whole thing - while I have some experience with ruby, not  
much but sufficient for rake/chef etc. 😉

On Thu, Mar 20, 2014 at 7:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:

> Hi Maciek,
> 
> Definitely agree about the docs. I have a Trello card open right now to  
> deal with that in the next few weeks.
> 
> ## Barthélemy's example will probably serve your purposes but in case it doesn't, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.
> 
> Eric
> 
> On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com))  
> wrote:
> 
> there already is such an issue - unattended 😉
> 
> On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont \<  
> [bvessemont@gmail.com](mailto:bvessemont@gmail.com)\> wrote:
> 
> > Ohai !
> > 
> > I'm working regularly with this cookbook's author. Don't hesitate to  
> > create a github issue asking for some doc if you feel the need to.
> > 
> > Actually I'm using this very simple resource to manage my server's eth0 :
> > 
> > network\_interfaces 'eth0' do  
> > target '10.10.16.203'  
> > mask '255.255.128.0'  
> > gateway '10.10.1.253'  
> > end
> > 
> > there is other options you can use, you'd better look at lwrp ressource  
> > file to understand how it can work, and what can be changed :  
> > attribute :device, kind\_of: String, name\_attribute: true
> > 
> > attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]
> > 
> > attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]
> > 
> > attribute :bond, kind\_of: [TrueClass, FalseClass, Array]
> > 
> > attribute :bond\_mode, kind\_of: String  
> > attribute :vlan\_dev, kind\_of: String  
> > attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true
> > 
> > attribute :bootproto, kind\_of: String  
> > attribute :target, kind\_of: String  
> > attribute :gateway, kind\_of: String
> > 
> > attribute :metric, kind\_of: Integer  
> > attribute :mtu, kind\_of: Integer  
> > attribute :mask, kind\_of: String
> > 
> > attribute :network, kind\_of: String  
> > attribute :broadcast, kind\_of: String  
> > attribute :pre\_up, kind\_of: String
> > 
> > attribute :up, kind\_of: String  
> > attribute :post\_up, kind\_of: String  
> > attribute :pre\_down, kind\_of: String
> > 
> > attribute :down, kind\_of: String  
> > attribute :post\_down, kind\_of: String  
> > attribute :custom, kind\_of: Hash
> > 
> > On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)wrote:
> > 
> > > Are there some usage examples? This cookbook's documentation is  
> > > severely lacking - I'm not proficient with Chef yet, so I'm having a hard  
> > > time understanding how to use it.
> > > 
> > > cheers,  
> > > Maciej
> > > 
> > > On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com)wrote:
> > > 
> > > > Not sure if this is useful for your particular case but if what  
> > > > you're trying to do is set up some existing physical NICs (or virtual NICs  
> > > > if you're in a cloud computing environment) there is a cookbook for that:
> > > > 
> > > > ## [GitHub - sous-chefs/network\_interfaces: Development repository for the network\_interfaces cookbook](https://github.com/redguide/network_interfaces)
> > > > 
> > > > Eric
> > > > 
> > > > On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com))  
> > > > wrote:
> > > > 
> > > > I'm going to take an initial whack at this, and say I "think" its  
> > > > going to be something like
> > > > 
> > > > node[network][interfaces].each do |nic|  
> > > > [whatever you want to do here]
> > > > 
> > > > Youll probably wanna add a bit of logic just after that first line to  
> > > > help ignore it is the nic is the lo nic.
> > > > 
> > > > Other will certainly improve on this.
> > > > 
> > > > On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal \<[mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)
> > > > 
> > > > > wrote:
> > > > 
> > > > > I'm looking for a way to configure N (N=3) ubuntu nodes with 2  
> > > > > network interfaces each - since I'm a complete newb, what is the proper way  
> > > > > to do it?
> > > > > 
> > > > > Regards,  
> > > > > Maciej
> > 
> > --  
> > Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
> > Ingénieur en informatique diplômé de l'UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Eric\_Herot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_herot/32/84_2.png) [@Eric\_Herot](https://discourse.chef.io/u/Eric_Herot)\
**Post date:** [March 21, 2014, 3:28pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/13 "2014-03-21T15:28:28Z")

</div>

Hi Maciek,

So there are a lot of possible ways to do this, but I suppose the first thing I’d need to know is whether these interfaces need to be set up with static addresses or dynamic ones, and whether all 4 interfaces in the example would need to have different setups.

The simplest thing to do would be to just define a both interfaces using DHCP in a single wrapper cookbook and then place that wrapper cookbook in the run list of both nodes. That might look something like this:

include\_recipe ‘network\_interfaces’

%w(eth0 eth1).each do |alias|  
network\_interface alias do  
bootproto 'dhcp’  
end  
end

Obviously if you want to specify static IPs per node that’s going to require some finagling. The right way to do it will be determined by exactly how you want to allocate IPs. If you can give me some feedback on this I might be able to give you some suggestions.

Almost any property that can be specified in the /etc/network/interfaces config file will be listed in the resource definition:

> <https://github.com/redguide/network_interfaces/blob/v1.0.0/resources/default.rb>

…And one day will also be listed in the README. 😉

Also, anything that is not included in that resources file can be added by setting the “custom” property with a hash.

E.g.

network\_interface ‘eth0’ do  
target '192.168.0.1’  
custom(  
‘myproperty1’ =\> ‘myvalue1’,  
‘myproperty2’ =\> ‘myvalue2’  
)  
end

Please let me know if any of that isn’t clear or if I left out something you need.

–  
Eric

On March 20, 2014 at 6:05:18 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

Hi Eric,

If you would be so kind and elaborate :

How would you configure multiple nodes with multiple interfaces using this cookbook? Can you give me a simple 2 nodes with 2 interfaces each example?

Please assume that I know little of chef and I’m trying to understand how to “model” the whole thing - while I have some experience with ruby, not much but sufficient for rake/chef etc. 😉

On Thu, Mar 20, 2014 at 7:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:  
Hi Maciek,

Definitely agree about the docs. I have a Trello card open right now to deal with that in the next few weeks.

## Barthélemy’s example will probably serve your purposes but in case it doesn’t, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.

Eric

On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

there already is such an issue - unattended 😉

On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont [bvessemont@gmail.com](mailto:bvessemont@gmail.com) wrote:  
Ohai !

I’m working regularly with this cookbook’s author. Don’t hesitate to create a github issue asking for some doc if you feel the need to.

Actually I’m using this very simple resource to manage my server’s eth0 :

network\_interfaces ‘eth0’ do  
target '10.10.16.203’  
mask '255.255.128.0’  
gateway '10.10.1.253’  
end

there is other options you can use, you’d better look at lwrp ressource file to understand how it can work, and what can be changed :  
attribute :device, kind\_of: String, name\_attribute: true  
attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]  
attribute :bond, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bond\_mode, kind\_of: String  
attribute :vlan\_dev, kind\_of: String  
attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true  
attribute :bootproto, kind\_of: String  
attribute :target, kind\_of: String  
attribute :gateway, kind\_of: String  
attribute :metric, kind\_of: Integer  
attribute :mtu, kind\_of: Integer  
attribute :mask, kind\_of: String  
attribute :network, kind\_of: String  
attribute :broadcast, kind\_of: String  
attribute :pre\_up, kind\_of: String  
attribute :up, kind\_of: String  
attribute :post\_up, kind\_of: String  
attribute :pre\_down, kind\_of: String  
attribute :down, kind\_of: String  
attribute :post\_down, kind\_of: String  
attribute :custom, kind\_of: Hash

On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
Are there some usage examples? This cookbook’s documentation is severely lacking - I’m not proficient with Chef yet, so I’m having a hard time understanding how to use it.

cheers,  
Maciej

On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:  
Not sure if this is useful for your particular case but if what you’re trying to do is set up some existing physical NICs (or virtual NICs if you’re in a cloud computing environment) there is a cookbook for that:

## [https://github.com/redguide/network\_interfaces](https://github.com/redguide/network_interfaces)

Eric

On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com)) wrote:

I’m going to take an initial whack at this, and say I “think” its going to be something like

node[network][interfaces].each do |nic|  
[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network interfaces each - since I’m a complete newb, what is the proper way to do it?

Regards,  
Maciej

–  
Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
Ingénieur en informatique diplômé de l’UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Maciek\_Misztal](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/maciek_misztal/32/351_2.png) [@Maciek\_Misztal](https://discourse.chef.io/u/Maciek_Misztal)\
**Post date:** [March 21, 2014, 5:19pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/14 "2014-03-21T17:19:36Z")

</div>

Hi Eric,

This seems to be the direction I want to follow, I now understand how are you achieving certain things, however I still don’t see how is this applied to multiple nodes? Let’s assume that each machine needs to have static IPs assigned to it’s NICs, how would you achieve that?

Best regards,

Maciej

Sent from Windows Mail

From: Eric Herot  
Sent: ‎Friday‎, ‎March‎ ‎21‎, ‎2014 ‎4‎:‎28‎ ‎PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)

Hi Maciek,

So there are a lot of possible ways to do this, but I suppose the first thing I’d need to know is whether these interfaces need to be set up with static addresses or dynamic ones, and whether all 4 interfaces in the example would need to have different setups.

The simplest thing to do would be to just define a both interfaces using DHCP in a single wrapper cookbook and then place that wrapper cookbook in the run list of both nodes. That might look something like this:

include\_recipe ‘network\_interfaces’

%w(eth0 eth1).each do |alias|

network\_interface alias do

```
bootproto 'dhcp'

```

end

end

Obviously if you want to specify static IPs per node that’s going to require some finagling. The right way to do it will be determined by exactly how you want to allocate IPs. If you can give me some feedback on this I might be able to give you some suggestions.

Almost any property that can be specified in the /etc/network/interfaces config file will be listed in the resource definition:

> <https://github.com/redguide/network_interfaces/blob/v1.0.0/resources/default.rb>

…And one day will also be listed in the README. 😉

Also, anything that is not included in that resources file can be added by setting the “custom” property with a hash.

E.g.

network\_interface ‘eth0’ do

target ‘192.168.0.1’

custom(

```
'myproperty1' => 'myvalue1',

'myproperty2' => 'myvalue2'

```

)

end

Please let me know if any of that isn’t clear or if I left out something you need.

–  
Eric

On March 20, 2014 at 6:05:18 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

Hi Eric,

If you would be so kind and elaborate :

How would you configure multiple nodes with multiple interfaces using this cookbook? Can you give me a simple 2 nodes with 2 interfaces each example?

Please assume that I know little of chef and I’m trying to understand how to “model” the whole thing - while I have some experience with ruby, not much but sufficient for rake/chef etc. 😉

On Thu, Mar 20, 2014 at 7:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:

Hi Maciek,

Definitely agree about the docs. I have a Trello card open right now to deal with that in the next few weeks.

Barthélemy’s example will probably serve your purposes but in case it doesn’t, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.

–  
Eric

On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

there already is such an issue - unattended 😉

On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont [bvessemont@gmail.com](mailto:bvessemont@gmail.com) wrote:

Ohai !

I’m working regularly with this cookbook’s author. Don’t hesitate to create a github issue asking for some doc if you feel the need to.

Actually I’m using this very simple resource to manage my server’s eth0 :

network\_interfaces ‘eth0’ do  
target '10.10.16.203’  
mask '255.255.128.0’  
gateway '10.10.1.253’  
end

there is other options you can use, you’d better look at lwrp ressource file to understand how it can work, and what can be changed :

attribute :device, kind\_of: String, name\_attribute: true

attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]

attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]

attribute :bond, kind\_of: [TrueClass, FalseClass, Array]

attribute :bond\_mode, kind\_of: String

attribute :vlan\_dev, kind\_of: String

attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true

attribute :bootproto, kind\_of: String

attribute :target, kind\_of: String

attribute :gateway, kind\_of: String

attribute :metric, kind\_of: Integer

attribute :mtu, kind\_of: Integer

attribute :mask, kind\_of: String

attribute :network, kind\_of: String

attribute :broadcast, kind\_of: String

attribute :pre\_up, kind\_of: String

attribute :up, kind\_of: String

attribute :post\_up, kind\_of: String

attribute :pre\_down, kind\_of: String

attribute :down, kind\_of: String

attribute :post\_down, kind\_of: String

attribute :custom, kind\_of: Hash

On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:

Are there some usage examples? This cookbook’s documentation is severely lacking - I’m not proficient with Chef yet, so I’m having a hard time understanding how to use it.

cheers,  
Maciej

On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:

Not sure if this is useful for your particular case but if what you’re trying to do is set up some existing physical NICs (or virtual NICs if you’re in a cloud computing environment) there is a cookbook for that:

> **[redguide/network\_interfaces](https://github.com/redguide/network_interfaces)**
>
> network\_interfaces - Cookbook to manage networking.

–  
Eric

On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com)) wrote:

I’m going to take an initial whack at this, and say I “think” its going to be something like

node[network][interfaces].each do |nic|

[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:

I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network interfaces each - since I’m a complete newb, what is the proper way to do it?

Regards,  
Maciej

–

Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
Ingénieur en informatique diplômé de l’UTC (Compiègne)

---

<div class="post-metadata">

**Author:** ![Eric\_Herot](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/eric_herot/32/84_2.png) [@Eric\_Herot](https://discourse.chef.io/u/Eric_Herot)\
**Post date:** [March 24, 2014, 10:46pm UTC](https://discourse.chef.io/t/how-do-i-configure-etc-network-interfaces-using-chef/5142/15 "2014-03-24T22:46:50Z")

</div>

[cleaned up excessive Re’s]

Hi Maciej,

Sorry to take so long to respond. Mapping IPs to nodes is probably going to be the most cumbersome part of this. The best way I can think of to do this (others are encouraged to chime in with better suggestions because mine feels a bit clunky) is either to create a data bag with node name to IP mappings and then have the server look up its own entry in the data bag at bootstrap and assign the IP accordingly, or to use Chef to manage a DHCP server and then assign the IPs from there.

Here’s how you would do it with a data bag:

my\_ips = data\_bag\_item(‘example\_networking\_bag’, ‘node\_ips’)[[node.name](http://node.name)]

include\_recipe ‘network\_interfaces’

my\_ips.each do |interface, if\_conf|  
network\_interface interface do  
target if\_conf[‘ipaddr’]  
mask if\_conf[‘netmask’]  
gateway if\_conf[‘gateway’]  
pre\_up ‘sleep 2’ # in keeping with default behavior on Debian/Ubuntu.  
end  
end  
…and the data bag item would look something like this:

{  
“id”: “node\_ips”,  
“my-first-node-name”: {  
“eth0”: {  
“ipaddr”: “192.168.1.2”,  
“netmask”: “255.255.255.0”,  
“gateway”: “192.168.1.1”  
},  
“eth1”: {  
“ipaddr”: “192.168.2.3”,  
“netmask”: “255.255.255.0”,  
“gateway”: “192.168.2.1”  
},  
},  
“my-second-node-name”: {  
“eth0”: {  
“ipaddr”: “192.168.1.3”,  
“netmask”: “255.255.255.0”,  
“gateway”: “192.168.1.1”  
},  
“eth1”: {  
“ipaddr”: “192.168.2.4”,  
“netmask”: “255.255.255.0”,  
“gateway”: “192.168.2.1”  
}  
}  
}  
Does that make sense?

–

Eric

On March 21, 2014 at 1:21:25 PM, [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

Hi Eric,

This seems to be the direction I want to follow, I now understand how are you achieving certain things, however I still don’t see how is this applied to multiple nodes? Let’s assume that each machine needs to have static IPs assigned to it’s NICs, how would you achieve that?

Best regards,  
Maciej

Sent from Windows Mail

From: Eric Herot  
Sent: ‎Friday‎, ‎March‎ ‎21‎, ‎2014 ‎4‎:‎28‎ ‎PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)

Hi Maciek,

So there are a lot of possible ways to do this, but I suppose the first thing I’d need to know is whether these interfaces need to be set up with static addresses or dynamic ones, and whether all 4 interfaces in the example would need to have different setups.

The simplest thing to do would be to just define a both interfaces using DHCP in a single wrapper cookbook and then place that wrapper cookbook in the run list of both nodes. That might look something like this:

include\_recipe ‘network\_interfaces’

%w(eth0 eth1).each do |alias|  
network\_interface alias do  
bootproto 'dhcp’  
end  
end

Obviously if you want to specify static IPs per node that’s going to require some finagling. The right way to do it will be determined by exactly how you want to allocate IPs. If you can give me some feedback on this I might be able to give you some suggestions.

Almost any property that can be specified in the /etc/network/interfaces config file will be listed in the resource definition:

> <https://github.com/redguide/network_interfaces/blob/v1.0.0/resources/default.rb>

…And one day will also be listed in the README. 😉

Also, anything that is not included in that resources file can be added by setting the “custom” property with a hash.

E.g.

network\_interface ‘eth0’ do  
target '192.168.0.1’  
custom(  
‘myproperty1’ =\> ‘myvalue1’,  
‘myproperty2’ =\> ‘myvalue2’  
)  
end

Please let me know if any of that isn’t clear or if I left out something you need.

–  
Eric

On March 20, 2014 at 6:05:18 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

Hi Eric,

If you would be so kind and elaborate :

How would you configure multiple nodes with multiple interfaces using this cookbook? Can you give me a simple 2 nodes with 2 interfaces each example?

Please assume that I know little of chef and I’m trying to understand how to “model” the whole thing - while I have some experience with ruby, not much but sufficient for rake/chef etc. 😉

On Thu, Mar 20, 2014 at 7:50 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:  
Hi Maciek,

Definitely agree about the docs. I have a Trello card open right now to deal with that in the next few weeks.

## Barthélemy’s example will probably serve your purposes but in case it doesn’t, please let me know if there are any specific questions I can answer in the mean time. I do not own the cookbook but I am a contributor to it.

Eric

On March 20, 2014 at 12:18:14 PM, Maciek Misztal ([mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com)) wrote:

there already is such an issue - unattended 😉

On Thu, Mar 20, 2014 at 1:53 PM, Barthélemy Vessemont [bvessemont@gmail.com](mailto:bvessemont@gmail.com) wrote:  
Ohai !

I’m working regularly with this cookbook’s author. Don’t hesitate to create a github issue asking for some doc if you feel the need to.

Actually I’m using this very simple resource to manage my server’s eth0 :

network\_interfaces ‘eth0’ do  
target '10.10.16.203’  
mask '255.255.128.0’  
gateway '10.10.1.253’  
end

there is other options you can use, you’d better look at lwrp ressource file to understand how it can work, and what can be changed :  
attribute :device, kind\_of: String, name\_attribute: true  
attribute :bridge, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bridge\_stp, kind\_of: [TrueClass, FalseClass]  
attribute :bond, kind\_of: [TrueClass, FalseClass, Array]  
attribute :bond\_mode, kind\_of: String  
attribute :vlan\_dev, kind\_of: String  
attribute :onboot, kind\_of: [TrueClass, FalseClass], default: true  
attribute :bootproto, kind\_of: String  
attribute :target, kind\_of: String  
attribute :gateway, kind\_of: String  
attribute :metric, kind\_of: Integer  
attribute :mtu, kind\_of: Integer  
attribute :mask, kind\_of: String  
attribute :network, kind\_of: String  
attribute :broadcast, kind\_of: String  
attribute :pre\_up, kind\_of: String  
attribute :up, kind\_of: String  
attribute :post\_up, kind\_of: String  
attribute :pre\_down, kind\_of: String  
attribute :down, kind\_of: String  
attribute :post\_down, kind\_of: String  
attribute :custom, kind\_of: Hash

On Wed, Mar 19, 2014 at 7:04 PM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
Are there some usage examples? This cookbook’s documentation is severely lacking - I’m not proficient with Chef yet, so I’m having a hard time understanding how to use it.

cheers,  
Maciej

On Wed, Mar 19, 2014 at 5:25 PM, Eric Herot [eric.opscode@herot.com](mailto:eric.opscode@herot.com) wrote:  
Not sure if this is useful for your particular case but if what you’re trying to do is set up some existing physical NICs (or virtual NICs if you’re in a cloud computing environment) there is a cookbook for that:

## [https://github.com/redguide/network\_interfaces](https://github.com/redguide/network_interfaces)

Eric

On March 19, 2014 at 12:09:24 PM, Kenneth Barry ([kbarry-x@tunein.com](mailto:kbarry-x@tunein.com)) wrote:

I’m going to take an initial whack at this, and say I “think” its going to be something like

node[network][interfaces].each do |nic|  
[whatever you want to do here]

Youll probably wanna add a bit of logic just after that first line to help ignore it is the nic is the lo nic.

Other will certainly improve on this.

On Wed, Mar 19, 2014 at 8:10 AM, Maciek Misztal [mmisztal1980@gmail.com](mailto:mmisztal1980@gmail.com) wrote:  
I’m looking for a way to configure N (N=3) ubuntu nodes with 2 network interfaces each - since I’m a complete newb, what is the proper way to do it?

Regards,  
Maciej

–  
Barthélemy Vessemont - [bvessemont@gmail.com](mailto:bvessemont@gmail.com)  
Ingénieur en informatique diplômé de l’UTC (Compiègne)
