1

I have two static IPs from my ISP. I want to hang a Pi4 on one of them, and connect it through a switch to one of the IPs provided. To be clear, suppose one of my IPs is 123.45.67.89 I want to plug my Pi into an unmanaged switch, and set it up to directly use that IP. The gateway would be 123.45.67.254

I previously had a Pi doing exactly that, but can't remember how I did it.

lar3ry
  • 21
  • 2
  • No more relevant to the Pi than any other Linux computer. Have you considered set up port forwarding on your router instead? Using a public IP address on your LAN doesn't look good to me. – MaxDZ8 Sep 13 '20 at 09:35
  • Well, it won't exactly be on a LAN, unless you call a single Pi on a switch, a LAN. – lar3ry Sep 13 '20 at 19:48

2 Answers2

2

There is an official side where you can find how to setup a static ip address on a Raspberry Pi:
TCP/IP networking.

Ingo
  • 42,097
  • 20
  • 85
  • 197
  • Thanks Max, but that shows how to set a static address on a LAN. Could I just use:

    static routers=123.45.67.254

    which is the gateway?

    – lar3ry Sep 13 '20 at 19:54
  • Got it. Just set routers =123.45.67.254 and it works like a champ. – lar3ry Sep 14 '20 at 06:07
  • @lar3ry Please create an answer with the solution and mark it as the accepted one with a click on the tick on its left side after two days. That prevents your Question from being shown as a unsolved Post to the community all the time and saves them/us a lot of work. – Ingo Sep 14 '20 at 11:37
  • Isn't that odd - that they would publish advice that's contrary to the published documentation? I suppose the Raspberry Pi Foundation employees don't read the fine manuals either! – Seamus Sep 17 '20 at 00:12
1

@MaxDZ8 pointed me to a site that told me to add the following entry to /etc/dhcpcd.conf:

interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.254
static domain_name_servers=192.168.0.254 8.8.8.8

This did not look like the solution I wanted, as my Pi is not connected to a router; only to an unmanaged switch. As it turned out, I added the following to /etc/dhcpcd.conf using my actual static IP and the gateway IP provided by my ISP.

interface eth0
static ip_address=123.45.67.89
static routers=123.45.67.254
static domain_name_servers=8.8.8.8

lar3ry
  • 21
  • 2