2016-09-22 12:43:57 +00:00
---
title: About the host Resource
2018-02-16 00:28:15 +00:00
platform: os
2016-09-22 12:43:57 +00:00
---
# host
2019-04-26 18:24:29 +00:00
Use the `host` Chef InSpec audit resource to test the name used to refer to a specific host and its availability, including the Internet protocols and ports over which that host name should be available.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.0.0 of InSpec.
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `host` resource block declares a host name, and then (depending on what is to be tested) a port and/or a protocol:
2017-10-04 19:34:02 +00:00
describe host('example.com', port: 80, protocol: 'tcp') do
it { should be_reachable }
it { should be_resolvable }
its('ipaddress') { should include '12.34.56.78' }
end
2016-09-22 12:43:57 +00:00
where
* `host()` must specify a host name and may specify a port number and/or a protocol
* `'example.com'` is the host name
* `port:` is the port number
2017-06-09 16:18:51 +00:00
* `protocol: 'name'` is the Internet protocol: TCP (`protocol: 'tcp'`), UDP (`protocol: 'udp'` or ICMP (`protocol: 'icmp'`))
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2018-02-27 00:21:32 +00:00
## Resource Properties
* `connection`, `ipaddress`, `protocol`, `socket`
<br>
## Resource Examples
2016-09-22 12:43:57 +00:00
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2016-09-22 12:43:57 +00:00
2018-02-27 00:21:32 +00:00
### ipaddress
The `ipaddress` matcher tests if a host name is resolvable to a specific IP address:
describe host('example.com') do
its('ipaddress') { should include '93.184.216.34' }
end
2016-09-27 19:03:23 +00:00
### Verify host name is reachable over a specific protocol and port number
2016-09-22 12:43:57 +00:00
2017-06-09 16:18:51 +00:00
describe host('example.com', port: 80, protocol: 'tcp') do
2016-09-22 12:43:57 +00:00
it { should be_reachable }
end
2016-09-27 19:03:23 +00:00
### Verify that a specific IP address can be resolved
2016-09-22 12:43:57 +00:00
2017-06-09 16:18:51 +00:00
describe host('example.com') do
2016-09-22 12:43:57 +00:00
it { should be_resolvable }
2018-02-27 00:21:32 +00:00
its('ipaddress') { should include '93.184.216.34' }
2016-09-22 12:43:57 +00:00
end
2017-07-05 14:45:30 +00:00
### Review the connection setup and socket contents when checking reachability
describe host('example.com', port: 12345, protocol: 'tcp') do
it { should be_reachable }
its('connection') { should_not match /connection refused/ }
its('socket') { should match /STATUS_OK/ }
end
2017-10-03 21:35:10 +00:00
<br>
## Matchers
2019-04-26 18:24:29 +00:00
This Chef InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2017-10-03 21:35:10 +00:00
### be_reachable
The `be_reachable` matcher tests if the host name is available:
it { should be_reachable }
### be_resolvable
The `be_resolvable` matcher tests for host name resolution, i.e. "resolvable to an IP address":
it { should be_resolvable }