0

One of my PC machines is conflicting with my raspberry pi because they're sharing the same local IP.

Editing the PC's static IP is not an option, lots of hard-coded things set to this IP.

I've set both the Pi's eth0 and wlan0 interfaces to static ip 192.168.1.22:

/etc/dhcp/dhclient.conf:

interface eth0
static ip_address=192.168.1.22/24
static routers=2001:520:ff02:12b::68
static domain_name_servers=2001:520:ff02:12b::68

interface wlan0
static ip_address=192.168.1.20/24
static routers=2001:520:ff02:12b::68
static domain_name_servers=2001:520:ff02:12b::68

PC uses 192.168.1.21

Pi should be using 192.168.1.22, but its wlan0 interface keeps getting set to 192.168.1.21:

default via 192.168.1.254 dev eth0 proto dhcp src **192.168.1.22** metric 100
default via 192.168.1.254 dev wlan0 proto dhcp src **192.168.1.21** metric 600

What am I doing wrong? How do I set the Pi's ethernet and wifi static IP addresses to 192.168.1.22?

EDIT: I changed the wlan0 static ip to 192.168.1.20 but it's still using 192.168.1.21...

EDIT 2: Script output:

[36m- Networking System
(B[0mNetworkManager active
networking active
[36m- IP addresses & routes
(B[0m1: 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 noprefixroute 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:65:3e:78 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.22/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
       valid_lft 79734sec preferred_lft 79734sec
    inet6 2001:569:5b0c:d500:3300:2bb5:7d7d:821c/64 scope global dynamic noprefixroute 
       valid_lft 14595sec preferred_lft 14295sec
    inet6 fe80::d3ac:38:75b1:c922/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:30:6b:2d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.21/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
       valid_lft 79740sec preferred_lft 79740sec
    inet6 2001:569:5b0c:d500:cb03:8354:c6bf:104b/64 scope global dynamic noprefixroute 
       valid_lft 14595sec preferred_lft 14295sec
    inet6 fe80::37b5:9170:5012:e133/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

default via 192.168.1.254 dev eth0 proto dhcp src 192.168.1.22 metric 100 
default via 192.168.1.254 dev wlan0 proto dhcp src 192.168.1.21 metric 600 
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.22 metric 100 
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.21 metric 600 
[36m- Network Devices
(B[0meth0
lo
wlan0
[36m- Connected WiFi
(B[0mPromotedNetwork
[36m- Available WiFi connections
(B[0mPromotedNetwork
PromotedNetwork
4
  • You can't assign the same IP address to two interfaces.
    – user68186
    Commented Mar 10 at 21:18
  • @user68186 even if I set the wlan0 static IP to a different IP, it's still being set to 192.168.1.21 for some reason. Commented Mar 10 at 21:51
  • Copy and paste the script given by @Milliways into a text editor. Save the file as letsfindout. Make the file executable with the command: chmod +x letsfindout. Then at the terminal enter the command ./letsfindout. Note the dot and slash before the file name. This will generate some output. Copy the generated output from the terminal and paste it directly into your question and format it as code using the {_} icon above the edit window.
    – user68186
    Commented Mar 10 at 23:52
  • I've updated the question with the script output. Commented Mar 11 at 0:08

1 Answer 1

0

You can't assign the same address to 2 interfaces (unless you use a bridge - in which case you assign the IP to the bridge).

Setting a static IP address is a Pi disease, rarely necessary on a network with a DHCP server. If you have some reason reserve in your router.


Try running the following to find out what you actually have

#! /bin/sh
# This script prints useful diagnostics for common Pi networking systems

# Function to print coloured headings
#  delete "tput" lines for plain output
print_head () {
 tput setaf 6
 echo $1
 tput sgr 0
}

checkactive () {
if [ $(systemctl is-active $1) = 'active' ]; then
    echo $1 'active'
fi
}

print_head "- Networking System"
# Check status of networking system
checkactive 'systemd-networkd'
checkactive 'dhcpcd'
checkactive 'NetworkManager'
checkactive 'networking'

print_head "- IP addresses & routes"
# Print IP addresses & routes
ip a
echo
ip r

print_head "- Network Devices"
ls /sys/class/net   # network devices

print_head "- Connected WiFi"
# Get SSID of connected WiFi (WRONG if AP!)
if [ -e /sys/class/net/wlan0 ]; then
    if [ $(systemctl is-active 'NetworkManager') = 'active' ]; then
        nmcli connection show |  awk '/wlan0/ {print $1}'
    else
        wpa_cli -i wlan0 status | grep -w ssid | awk -F'[=]' '{print $2}'
    fi
fi

print_head "- Available WiFi connections"
if [ -e /sys/class/net/wlan0 ]; then
    if [ $(systemctl is-active 'NetworkManager') = 'active' ]; then
        nmcli connection show |  awk '/wifi/ {print $1}'
    else
        wpa_cli list_networks | awk '/any/ {print $2}'
    fi
fi

You are using NetworkManager so anything you put in other config files is irrelevant. What you put in dhclient.conf actually looks like a dhcpcd configuration file and certainly doesn't belong there and would't set an IP address (even if it was used).

See How do I set up networking on Raspberry Pi OS - Bookworm

5
  • My router does not have this setting unfortunately. Setting the wlan0 static IP address to another ip (say 192.168.1.20) still yields the same result: default via 192.168.1.254 dev eth0 proto dhcp src 192.168.1.22 metric 100 default via 192.168.1.254 dev wlan0 proto dhcp src 192.168.1.21 metric 600 It for some reason wants to hang on to 192.168.1.21 for some reason. Can't figure out why. Commented Mar 10 at 21:49
  • This is the only file I've edited to attempt to assign a static IP to my raspberry pi. I want my raspberry pi to have the static IP (ethernet) of 192.168.1.22 and the wlan0 of 192.168.1.20 Using command systemctl dhcpcd gives me this error: "Unknown command verb dhcpcd." Can't find a solution on how to assign the static ip other than this file.. Commented Mar 10 at 22:05
  • As I said the original command you gave me gave an error, I'm new to linux. This is the output for the command: "Unit dhcpcd.service could not be found.". If you want some kind of diagnostic you're going to have to provide me a command that outputs that because I don't know what command to issue to do that. Commented Mar 10 at 23:00
  • Updated question with your recent script Commented Mar 11 at 0:08
  • Thank you, I looked up the documentation and set the static IP through NetworkManager instead. Commented Mar 11 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.