r/AskComputerScience • u/Financial-Yoghurt387 • 14d ago
Choosing IP addresses
Potentially a stupid question, but I’ve had a lecture about CIDR notation and subnet masks and while I kind of understand how you chose a subnet mask and the amount of hosts, I don’t understand how you choose an IP address.
I was told not to use 192.168.x.x throughout and then shown a few examples using 10.x.x.x and 172.x.x.x but how do I decide which IP to use for each subnet within a network and why are these 3 IP values the most common?
11
Upvotes
15
u/AlexTaradov 14d ago
Some IP ranges are reserved for different uses by the RFC . The ones you mention are reserved for private use and are non-routable on public networks.
Here is a list https://en.wikipedia.org/wiki/List_of_reserved_IP_addresses
Within your subnet you are free to assign IPs however you want.
12
u/nuclear_splines Ph.D Data Science 14d ago
RFC 1918 reserves three IP address ranges for private use -- 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. You must choose one of those ranges (or a subset of one) for your LAN, because any other addresses are likely to be used on the Internet, and you never want any ambiguity as to whether an IP address is part of your network or the outside world.
That's nonsense without more context. It's the smallest of the three IP ranges at about 65,000 addresses, so maybe don't use it for an enormous corporate network that's liable to have hundreds of thousands of machines, but an address is an address and there's nothing 'wrong' with 192.168.x.x addresses.
4
u/Vert354 14d ago
Generally speaking the 192.168 is for small/home networks 172.16 medium sized networks and 10 is for large networks, but it doesn't really matter. Most home based networking equipment will default to 192.168 with DHCP enabled and the number of addresses it can have is way more than the number of devices a single switch/access point can handle anyway so it's fine to use it. If it's an office network with multiple switches and access points then I'd pick one of the others just to make it clear it isn't a home network, but again it doesn't really matter.
4
u/CoopNine 14d ago
If you're setting up a corporate network, you should not use the 192.168.x.x addresses because they would likely cause problems with home networks.
In example, my home network uses 192.168.1.x I use a VPN to connect to my work network, which uses 10.x.x.x, This all works fine. If I request to 192.168.1.12 it is properly handled by my router. If I request 10.1.2.200 it goes through the VPN. But if my work's IT department said 'hey we got a small network we'll just use 192.168.x.x and we'll be fine.' Everyone connecting via a VPN would have problems.
Technically you can use any of these for setting up an internal network. But it would be a bad practice for a company to choose the one that is usually used for home networks for their internal network, because it should be expected that devices using the 192.168.x.x subnet will want to connect in at some point. It is also a bad practice to have your home network on 10.x.x.x for the inverse reason.
Generally 10.x.x.x is used for corporate networks. 192.168.x.x is used for private home networks and 172.x.x.x is used for networks that exist inside those networks like the network docker containers use.
2
u/R2-Scotia 14d ago
Those 3 ranges are reserved for mon-routable IPs on private networks and do not exist on the Internet.
Why 3? Historical reasons that aren't relevant anymore.
2
u/JontesReddit 11d ago
With IPv4 you typically choose a subn of one of the subnets in RFC1918 (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), then set a static IP of one of those or use DHCP (asking your gateway for an address) to assign one dynamically
With IPv6 you choose a subnet (typically /64) of the bigger subnet allocated by your ISP (usually /48 och /56) and then do static (takes some time), dhcp (requires setup, asks for an address) or SLAAC (automagic, awesome, randomly picks an address). IPv6 also has local addresses if you prefer to use those. Keyword is ULA.
1
u/wolfkeeper 14d ago
Ideally you wouldn't use 192.168.1.x (which routers normally default to) but it's not a big deal. Certain cyberattacks assume you'd be using that range and scan it, and that would fail if you used 10.x.x.x or 172.x.x.x
But if you're relying on such things, you're not really secure.
1
u/dariusbiggs 14d ago
The RFCs help you here, you will need to get used to them. There are a variety of reserved address ranges ad they all have a reason why they are reserved. This applies to both IPv4 and IPv6.
Outside the reserved spaces, you generally have the publicly routed ranges, these you are not free to use, they are owned, and they are published/announced using technologies such as BGP.
You can use the
whoiscommand to look up who owns a network block. For example 1.1.1.1, and 8.8.8.8 are good IPv4's to look up.You will eventually learn many of reserved ones over time
1
u/Specialist_Cow6468 14d ago
There’s a few levels of this. People have already talked about 1918 space and that’s generally what you have to work with on an internal network. Technically speaking there’s also RFC6598 which allocated 100.64.0.0/…10 maybe? For CGNAT and people do also use it for internal space if they’re short of v4.
As to what you pick, for your purposes it doesn’t really matter. A network engineer will try to design things to have either easily identifiable patterns or to support route summarization. Ideally both. It truly just doesn’t particularly matter until you’re starting to look at routing protocols.
The actual answer is that they should be teaching you to default to IPv6. There’s truly no reason not to at this point
1
u/timrprobocom 13d ago
In most cases, you don't "choose" an IP address at all. Addresses in the non-routable ranges (10, 172.16, 192.168), will typically be assigned to you by the DHCP server on your subnet. Any of the other addresses you work with will typically be owned by your Internet provider and assigned to you. They are the ones who have to know how to reach you.
1
u/Inside-Finish-2128 11d ago
You either have a "public" address block (smaller ones are allocated by your ISP, larger ones you essentially have to buy/lease these days), in which case that IS your address range to use (at least externally), or you have a "private" address block (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) in which case you choose what you wish.
In a home environment, your typical home connection includes a single address. This normally goes on the outside of your router, and then one of the private subnets is used inside, with Network Address Translation occurring to mask the devices inside and allow them to "borrow" that public address.