Skip to content

Instantly share code, notes, and snippets.

@atomlab
Created March 17, 2020 22:50
Show Gist options
  • Save atomlab/acb8a53d33dde3477c018c034d06fe14 to your computer and use it in GitHub Desktop.
Save atomlab/acb8a53d33dde3477c018c034d06fe14 to your computer and use it in GitHub Desktop.
How can I match a CIDR range for an SSH config host entry?
all hosts matching 10.2.?.* (i.e. 10.2.0.0–10.2.9.255)
all hosts matching 10.2.??.* (i.e. 10.2.10.0–10.2.99.255)
all hosts matching 10.2.10?.* (i.e. 10.2.100.0–10.2.109.255)
all hosts matching 10.2.11?.* (i.e. 10.2.110.0–10.2.119.255)
all hosts matching 10.2.12?.* EXCEPT the ones matching 10.2.128.* and 10.12.129.* (and remember that the exclusion must come first!)

Example ~/.ssh/config

Host "10.2.?.*","10.2.??.*", "10.2.10?.*","10.2.11?.*","!10.2.128.*","!10.2.129.*","10.2.12?.*"
  User root
  IdentityFile ~/.ssh/id_rsa

link: https://serverfault.com/a/803906

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment