In 3.4.2+, you can use Line2D (add at least two points) and then specify a Texture and set 'Texture Mode' to 'Tile'. Super easy and works really well. You can even drag the ends around in your editor.
As for what to use for the texture, here's a an example: Make a png that is 16x4. Make it gray on the left half and then transparent on the right. Save and reference this as your Texture. Make sure to import your texture with Repeat. You can then play with other settings like Width and Self_Modulate.
Here's a gdscript example if you want to do it from code instead. node1 and node2 are two existing objects in the scene that I want to draw a dashed line between.
var line = Line2D.new()
line.texture = load("res://assets/map/dotted-line.png")
line.texture_mode = Line2D.LINE_TEXTURE_TILE
var poolVectorArray : PoolVector2Array = 
line.points = poolVectorArray
P.S. If you want to do a dotted line, just change your texture so half is a filled circle and the other half is transparent.