2016-09-22 12:43:57 +00:00
---
title: About the host Resource
---
# host
Use the `host` 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-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:
.. code-block:: ruby
describe host('example.com', port: 80, proto: 'tcp') do
it { should be_reachable }
end
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
* `proto: 'name'` is the Internet protocol: TCP (`proto: 'tcp'`), UDP (`proto: 'udp'` or ICMP (`proto: 'icmp'`))
* `be_reachable` is a valid matcher for this resource
2016-09-27 19:03:23 +00:00
## Matchers
2016-09-22 12:43:57 +00:00
This InSpec audit resource has the following matchers:
2016-09-27 19:03:23 +00:00
### be
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_be" %>
2016-09-27 19:03:23 +00:00
### be_reachable
2016-09-22 12:43:57 +00:00
The `be_reachable` matcher tests if the host name is available:
it { should be_reachable }
2016-09-27 19:03:23 +00:00
### be_resolvable
2016-09-22 12:43:57 +00:00
The `be_resolvable` matcher tests for host name resolution, i.e. "resolvable to an IP address":
it { should be_resolvable }
2016-09-27 19:03:23 +00:00
### cmp
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_cmp" %>
2016-09-27 19:03:23 +00:00
### eq
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_eq" %>
2016-09-27 19:03:23 +00:00
### include
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_include" %>
2016-09-27 19:03:23 +00:00
### ipaddress
2016-09-22 12:43:57 +00:00
The `ipaddress` matcher tests if a host name is resolvable to a specific IP address:
its('ipaddress') { should include '93.184.216.34' }
2016-09-27 19:03:23 +00:00
### match
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_match" %>
2016-09-27 19:03:23 +00:00
## Examples
2016-09-22 12:43:57 +00:00
The following examples show how to use this InSpec audit resource.
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
describe host('example.com', port: 53, proto: 'udp') do
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
describe host('example.com', port: 80, proto: 'tcp') do
it { should be_resolvable }
its('ipaddress') { should include '192.168.1.1' }
end