The rocket science behind assigning static IP address to a server?

Joined
Apr 16, 2023
Messages
167
Reaction score
20
Credits
1,635
Code:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:7c:17:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.73/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
       valid_lft 85955sec preferred_lft 85955sec
    inet6 2400:1a00:b020:4822:a00:27ff:fe7c:1730/64 scope global dynamic noprefixroute
       valid_lft 820sec preferred_lft 820sec
    inet6 fe80::a00:27ff:fe7c:1730/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Assume this scenario.
As per jodies calculator,

I can use any host ip ranging from 192.168.1.1 to 192.168.1.254

But when I randomly select ip address like 192.168.1.10 or say 1.69, the server doesn't get access to the internet?

I mean I can open the server, the serve can network with other such servers but not with the internet.

The ping 8.8.8.8 will show(in case of 1.10 ip):
- reply from 192.168.1.10 destination host unreachable.


I feel like there's some rocket science going behind that I am not understanding. Can anyone explain? Or am I trying to do the impossible?
 


I choosed the same IP that was assigned when bridged, and still I can't connect to internet? I'll share the logs.
[root@localhost ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.1.73 icmp_seq=1 Destination Host Unreachable
From 192.168.1.73 icmp_seq=2 Destination Host Unreachable
From 192.168.1.73 icmp_seq=3 Destination Host Unreachable
From 192.168.1.73 icmp_seq=4 Destination Host Unreachable
From 192.168.1.73 icmp_seq=5 Destination Host Unreachable
From 192.168.1.73 icmp_seq=6 Destination Host Unreachable
From 192.168.1.73 icmp_seq=7 Destination Host Unreachable
From 192.168.1.73 icmp_seq=8 Destination Host Unreachable
From 192.168.1.73 icmp_seq=9 Destination Host Unreachable
From 192.168.1.73 icmp_seq=10 Destination Host Unreachable


I am using deprecated ifcfg-enp0s3 file(Don't @ me for that because I've not yet learnt the modern network manager)

TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="enp0s3"
DEVICE="enp0s3"
ONBOOT="yes"
ETHTOOL_OPTS="autoneg on"
IPADDR="192.168.1.73"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"

This is my config.
 
Found the culprit. BUT I've a big question.
The culprit was the gateway at the moment was 192.168.1.254 instead of 192.168.1.1.
BUT BUT
In my VMs with default gateway still as 192.168.1.1, the internet is still working.
I leave this question to network gods.
 
I use a secondary router, in addition to the one provided by my ISP, to keep my linux machines on their own subnet. I have this router's dhcp server configured to give each host a known IP address based upon its mac address.

I used to do network config with static IP addresses on each host using ifconfig, route and /etc/resolv.conf - but then I got lazy.
 
bottom line..... 4 parts to all IP setup and without all 4 you will not get internet.
1... IP address (this is obvious and must be in the IP pool)
2... Gateway (this is generally the IP address of the router)
3... Subnet mask.. .(usually 255.255.255.0) for most applications, Much more complex but not for here.
4... DNS (this is domain name service used to get IP from domain names) 8.8.8.8 and 8.8.4.4 are google and stable

when you have DHCP active and the IP is given from the router you get everything. If you want it stable and static you have to fill in each field correctly. With this information you should be able to easily set up static IP, but remember each computer IP address must be unique.
here is an example

1.. 192.168.1.14 computer IP address I assigned (outside of DHCP pool we do not want duplicates)
2.. 192.168.1.1 address of the router on the same segment
3.. 255.255.255.0 just leave this alone
4.. 8.8.8.8 google DNS server (sometimes this is the same as gateway)
 

Members online


Top