After you have written a fresh Raspbian image to your SD card, mount the SD card. If it isn't visible in File Explorer, just remove the card from the slot and reinsert it after 10 seconds or so.
Open the SD card, then find and open the file cmdline.txt
in Notepad. Save a copy of it, name it something like cmdline-original.txt
.
It will look something like this:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh
Change it to this (assuming your IP will be 192.168.1.145 as in your example):
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh ip=192.168.1.145
If you've already booted the Raspberry Pi off of this SD card once, you may not have the section init=/usr/lib/raspi-config/init_resize.sh
but just put your ip=192.168.1.145
bit on the end of the line anyway. It should still have only the one line. Don't let it break across multiple lines.
This is not the preferred way of setting your IP, and the use of /etc/network/interfaces
has been depreciated in favor of /etc/dhcpcd.conf
, so after you succeed in connecting to the Pi you need to open the file /etc/dhcpcd.conf
and put your IP address in it. If you don't feel comfortable using console-based text editors yet, you can use the following command in your console to insert the IP address info you specified:
sudo tee -a << EOF /etc/dhcpcd.conf > /dev/null
interface eth0
static ip_address=192.168.1.145/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
EOF
This is an expanded version of Widi Widiyanto's answer. I am not able to comment directly, so I posted it like this. Also, don't forget to restore your cmdline.txt
file to it's original state.